aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build.gradle1
-rw-r--r--src/main/java/com/anysoftkeyboard/ui/settings/MainFragment.java78
-rw-r--r--src/main/res/layout/main_fragment_top_info_layout.xml1
3 files changed, 73 insertions, 7 deletions
diff --git a/build.gradle b/build.gradle
index 78e806c95..e064cd47a 100644
--- a/build.gradle
+++ b/build.gradle
@@ -182,6 +182,7 @@ dependencies {
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:recyclerview-v7:23.1.0'
compile 'com.android.support:support-annotations:23.1.0'
+ compile 'com.android.support:palette-v7:23.1.0'
compile 'com.github.menny:Chauffeur:0.0.7'
compile fileTree(dir: 'libs', include: '*.jar')
diff --git a/src/main/java/com/anysoftkeyboard/ui/settings/MainFragment.java b/src/main/java/com/anysoftkeyboard/ui/settings/MainFragment.java
index 6c2c7d981..207f9c904 100644
--- a/src/main/java/com/anysoftkeyboard/ui/settings/MainFragment.java
+++ b/src/main/java/com/anysoftkeyboard/ui/settings/MainFragment.java
@@ -3,12 +3,19 @@ package com.anysoftkeyboard.ui.settings;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.Color;
import android.graphics.drawable.AnimationDrawable;
+import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
+import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
+import android.support.v4.content.ContextCompat;
+import android.support.v7.graphics.Palette;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.method.LinkMovementMethod;
@@ -34,6 +41,7 @@ public class MainFragment extends Fragment {
private static final String TAG = "MainFragment";
private AnimationDrawable mNotConfiguredAnimation = null;
+ private AsyncTask<Drawable, Void, Palette.Swatch> mPaletteTask;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
@@ -136,11 +144,8 @@ public class MainFragment extends Fragment {
View notConfiguredBox = getView().findViewById(R.id.not_configured_click_here);
//checking if the IME is configured
final Context context = getActivity().getApplicationContext();
- //checking the default IME
- final boolean isDefaultIME;
- isDefaultIME = SetupSupport.isThisKeyboardSetAsDefaultIME(context);
- if (isDefaultIME) {
+ if (SetupSupport.isThisKeyboardSetAsDefaultIME(context)) {
notConfiguredBox.setVisibility(View.GONE);
} else {
notConfiguredBox.setVisibility(View.VISIBLE);
@@ -154,13 +159,72 @@ public class MainFragment extends Fragment {
ImageView screenShotHolder = (ImageView) getView().findViewById(R.id.keyboard_screen_shot);
if (themeScreenShot == null)
- screenShotHolder.setBackgroundResource(R.drawable.lean_dark_theme_screenshot);
- else
- screenShotHolder.setImageDrawable(themeScreenShot);
+ themeScreenShot = ContextCompat.getDrawable(getActivity(), R.drawable.lean_dark_theme_screenshot);
+ screenShotHolder.setImageDrawable(themeScreenShot);
+ mPaletteTask = new AsyncTask<Drawable, Void, Palette.Swatch>() {
+ @Override
+ protected Palette.Swatch doInBackground(Drawable... params) {
+ Bitmap bitmap = drawableToBitmap(params[0]);
+ Palette p = Palette.from(bitmap).generate();
+ Palette.Swatch highestSwatch = null;
+ for (Palette.Swatch swatch : p.getSwatches()) {
+ if (highestSwatch == null || highestSwatch.getPopulation() < swatch.getPopulation())
+ highestSwatch = swatch;
+ }
+ return highestSwatch;
+ }
+
+ @Override
+ protected void onPostExecute(Palette.Swatch swatch) {
+ super.onPostExecute(swatch);
+ if (!isCancelled()) {
+ if (swatch != null) {
+ final int backgroundRed = Color.red(swatch.getRgb());
+ final int backgroundGreed = Color.green(swatch.getRgb());
+ final int backgroundBlue = Color.blue(swatch.getRgb());
+ final int backgroundColor = Color.argb(128/*50% alpha*/, backgroundRed, backgroundGreed, backgroundBlue);
+ TextView gplusLink = (TextView) getView().findViewById(R.id.ask_gplus_link);
+ gplusLink.setTextColor(swatch.getTitleTextColor());
+ gplusLink.setBackgroundColor(backgroundColor);
+
+ TextView subtitle = (TextView) getView().findViewById(R.id.main_settings_hero_sub_title);
+ subtitle.setTextColor(swatch.getBodyTextColor());
+ subtitle.setBackgroundColor(backgroundColor);
+ }
+ }
+ }
+ }.execute(themeScreenShot);
if (mNotConfiguredAnimation != null)
mNotConfiguredAnimation.start();
}
+ @Override
+ public void onStop() {
+ super.onStop();
+ mPaletteTask.cancel(false);
+ mPaletteTask = null;
+ }
+ private static Bitmap drawableToBitmap(Drawable drawable) {
+ Bitmap bitmap;
+
+ if (drawable instanceof BitmapDrawable) {
+ BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
+ if (bitmapDrawable.getBitmap() != null) {
+ return bitmapDrawable.getBitmap();
+ }
+ }
+
+ if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
+ bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888); // Single color bitmap will be created of 1x1 pixel
+ } else {
+ bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
+ }
+
+ Canvas canvas = new Canvas(bitmap);
+ drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
+ drawable.draw(canvas);
+ return bitmap;
+ }
} \ No newline at end of file
diff --git a/src/main/res/layout/main_fragment_top_info_layout.xml b/src/main/res/layout/main_fragment_top_info_layout.xml
index 08352826f..597fc1632 100644
--- a/src/main/res/layout/main_fragment_top_info_layout.xml
+++ b/src/main/res/layout/main_fragment_top_info_layout.xml
@@ -29,6 +29,7 @@
<TextView
style="@style/Ask.Text.Normal.Shadow"
+ android:id="@+id/main_settings_hero_sub_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"