List of usage examples for android.graphics Color BLACK
int BLACK
To view the source code for android.graphics Color BLACK.
Click Source Link
From source file:com.apache.fastandroid.novel.view.readview.PageFactory.java
public PageFactory(Context context, int width, int height, int fontSize, String bookId, List<BookMixAToc.mixToc.Chapters> chaptersList) { mContext = context;/*from w w w . j a va 2 s .c om*/ mWidth = width; mHeight = height; mFontSize = fontSize; mLineSpace = mFontSize / 5 * 2; mNumFontSize = DimensUtil.dp2px(context, 16); marginWidth = DimensUtil.dp2px(context, 15); marginHeight = DimensUtil.dp2px(context, 15); mVisibleHeight = mHeight - marginHeight * 2 - mNumFontSize * 2 - mLineSpace * 2; mVisibleWidth = mWidth - marginWidth * 2; mPageLineCount = mVisibleHeight / (mFontSize + mLineSpace); rectF = new Rect(0, 0, mWidth, mHeight); mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mPaint.setTextSize(mFontSize); mPaint.setTextSize(ContextCompat.getColor(context, R.color.chapter_content_day)); mPaint.setColor(Color.BLACK); mTitlePaint = new Paint(Paint.ANTI_ALIAS_FLAG); mTitlePaint.setTextSize(mNumFontSize); mTitlePaint.setColor(ContextCompat.getColor(FrameworkApplication.getContext(), R.color.chapter_title_day)); timeLen = (int) mTitlePaint.measureText("00:00"); percentLen = (int) mTitlePaint.measureText("00.00%"); // Typeface typeface = Typeface.createFromAsset(context.getAssets(),"fonts/FZBYSK.TTF"); // mPaint.setTypeface(typeface); // mNumPaint.setTypeface(typeface); this.bookId = bookId; this.chaptersList = chaptersList; time = dateFormat.format(new Date()); }
From source file:com.example.android.foldinglayout.FoldingLayoutActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_fold); mImageView = (ImageView) findViewById(R.id.image_view); mImageView.setPadding(ANTIALIAS_PADDING, ANTIALIAS_PADDING, ANTIALIAS_PADDING, ANTIALIAS_PADDING); mImageView.setScaleType(ImageView.ScaleType.FIT_XY); mImageView.setImageDrawable(getResources().getDrawable(R.drawable.image)); if (hasApiLevel(Build.VERSION_CODES.ICE_CREAM_SANDWICH)) { initTextureView();/*from ww w . j av a2 s . com*/ } mAnchorSeekBar = (SeekBar) findViewById(R.id.anchor_seek_bar); mFoldLayout = (FoldingLayout) findViewById(R.id.fold_view); mFoldLayout.setBackgroundColor(Color.BLACK); mFoldLayout.setFoldListener(mOnFoldListener); mTouchSlop = ViewConfiguration.get(this).getScaledTouchSlop(); mAnchorSeekBar.setOnSeekBarChangeListener(mSeekBarChangeListener); mScrollGestureDetector = new GestureDetector(this, new ScrollGestureDetector()); mItemSelectedListener = new ItemSelectedListener(); mDefaultPaint = new Paint(); mSepiaPaint = new Paint(); ColorMatrix m1 = new ColorMatrix(); ColorMatrix m2 = new ColorMatrix(); m1.setSaturation(0); m2.setScale(1f, .95f, .82f, 1.0f); m1.setConcat(m2, m1); mSepiaPaint.setColorFilter(new ColorMatrixColorFilter(m1)); }
From source file:com.jigarmjoshi.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (SimpleDatabaseUtil.isFirstApplicationStart(this)) { Log.i(MainActivity.class.getSimpleName(), "creating database for the first time"); SQLiteSimple databaseSimple = new SQLiteSimple(this, DATABASE_VERSION); databaseSimple.create(Report.class, LastLocation.class); } else if (SimpleDatabaseUtil.isFirstStartOnAppVersion(this, DATABASE_VERSION)) { Log.i(MainActivity.class.getSimpleName(), "creating database for the first time for this version " + DATABASE_VERSION); SQLiteSimple databaseSimple = new SQLiteSimple(this, DATABASE_VERSION); databaseSimple.create(Report.class, LastLocation.class); }// w w w.j a v a 2 s.c o m // initialize services EntryDao.getInstance(this); LastLocationDao.getInstance(this); // scheduler mgr = (AlarmManager) getSystemService(ALARM_SERVICE); Intent i = new Intent(this, LocationPoller.class); com.jigarmjoshi.service.LocationManager locationManager = com.jigarmjoshi.service.LocationManager .getInstance(getApplicationContext()); List<String> providers = locationManager.getAllProviders(); boolean fusedSupported = false; for (String provider : providers) { if (com.jigarmjoshi.service.LocationManager.FUSED_PROVIDER.equals(provider)) { fusedSupported = true; break; } } i.putExtra(LocationPoller.EXTRA_INTENT, new Intent(this, com.jigarmjoshi.reciever.LocationReceiver.class)); i.putExtra(LocationPoller.EXTRA_PROVIDER, (fusedSupported ? LocationManager.FUSED_PROVIDER : LocationManager.GPS_PROVIDER)); pi = PendingIntent.getBroadcast(this, 0, i, 0); mgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, 0, Long.parseLong(ConfigService.get(ConfigService.GPS_TASK_INTERVAL, "40000")), pi); // upload task Timer timer = new Timer(); TimerTask timerTask = new UploaderTask(this); timer.schedule(timerTask, 0, Long.parseLong(ConfigService.get(ConfigService.UPLOAD_TASK_INTERVAL, "40000"))); selectedTextView = new TextView(this); selectedTextView.setTextColor(Color.BLACK); selectedTextView.setGravity(Gravity.CENTER); selectedTextView.setPaintFlags(Paint.FAKE_BOLD_TEXT_FLAG); unSelectedTextView = new TextView(this); unSelectedTextView.setTextColor(Color.GRAY); unSelectedTextView.setGravity(Gravity.CENTER); unSelectedTextView.setPaintFlags(Paint.FAKE_BOLD_TEXT_FLAG); // create if first time getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY); actionBar = getActionBar(); actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#40808080"))); actionBar.setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor("#40808080"))); setContentView(R.layout.activity_main); // Initilization viewPager = (ViewPager) findViewById(R.id.pager); mAdapter = new TabsPagerAdapter(getSupportFragmentManager()); viewPager.setAdapter(mAdapter); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // Adding Tabs boolean first = false; for (String tab_name : tabs) { Tab tab = actionBar.newTab().setText(tab_name).setTabListener(this); if (first) { first = false; selectedTextView.setText(tab.getText().toString().toUpperCase(Locale.getDefault())); tab.setCustomView(selectedTextView); } else { unSelectedTextView.setText(tab.getText().toString().toUpperCase(Locale.getDefault())); tab.setCustomView(unSelectedTextView); } actionBar.addTab(tab); } /** * on swiping the viewpager make respective tab selected * */ viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageSelected(int position) { // on changing the page // make respected tab selected actionBar.setSelectedNavigationItem(position); } @Override public void onPageScrolled(int arg0, float arg1, int arg2) { } @Override public void onPageScrollStateChanged(int arg0) { } }); Toast.makeText(this, getString(R.string.wait_gps), Toast.LENGTH_LONG).show(); }
From source file:com.ryan.ryanreader.activities.MainActivity.java
@Override protected void onCreate(final Bundle savedInstanceState) { // //w w w . j ava 2 s. c o m PrefsUtility.applyTheme(this); OptionsMenuUtility.fixActionBar(this, getString(R.string.app_name)); sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); // sharedPreferences.registerOnSharedPreferenceChangeListener(this); // final boolean solidblack = PrefsUtility.appearance_solidblack(this, sharedPreferences) && PrefsUtility.appearance_theme(this, sharedPreferences) == PrefsUtility.AppearanceTheme.NIGHT; super.onCreate(savedInstanceState); twoPane = General.isTablet(this, sharedPreferences); final View layout; // ? if (twoPane) layout = getLayoutInflater().inflate(R.layout.main_double); else layout = getLayoutInflater().inflate(R.layout.main_single); if (solidblack) layout.setBackgroundColor(Color.BLACK); setContentView(layout); // ? doRefresh(RefreshableFragment.MAIN, false); RedditAccountManager.getInstance(this).addUpdateListener(this); PackageInfo pInfo = null; try { pInfo = getPackageManager().getPackageInfo(getPackageName(), 0); } catch (PackageManager.NameNotFoundException e) { throw new RuntimeException(e); } final int appVersion = pInfo.versionCode; if (!sharedPreferences.contains("firstRunMessageShown")) { new AlertDialog.Builder(this).setTitle(R.string.firstrun_login_title) .setMessage(R.string.firstrun_login_message) .setPositiveButton(R.string.firstrun_login_button_now, new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog, final int which) { new AccountListDialog().show(MainActivity.this); } }).setNegativeButton(R.string.accounts_anon, null).show(); final SharedPreferences.Editor edit = sharedPreferences.edit(); edit.putString("firstRunMessageShown", "true"); edit.commit(); } else if (sharedPreferences.contains("lastVersion")) { if (sharedPreferences.getInt("lastVersion", 0) != appVersion) { General.quickToast(this, "Updated to version " + pInfo.versionName); sharedPreferences.edit().putInt("lastVersion", appVersion).commit(); ChangelogDialog.newInstance().show(this); } } else { sharedPreferences.edit().putInt("lastVersion", appVersion).commit(); ChangelogDialog.newInstance().show(this); } Globals.NETWORK_ENABLE = Globals.isConnect(this);// if (Globals.AD_MODE && Globals.NETWORK_ENABLE) { // initADView(); } }
From source file:com.mbientlab.metawear.app.HomeFragment.java
@Override public void onViewCreated(final View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); RadioButton temp = (RadioButton) view.findViewById(R.id.switch_radio_pressed); temp.setEnabled(false);//from ww w . j ava 2 s. c o m temp.setTextColor(Color.BLACK); temp = (RadioButton) view.findViewById(R.id.switch_radio_released); temp.setEnabled(false); temp.setTextColor(Color.BLACK); view.findViewById(R.id.led_red_on).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { configureChannel(ledModule.configureColorChannel(Led.ColorChannel.RED)); ledModule.play(true); } }); view.findViewById(R.id.led_green_on).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { configureChannel(ledModule.configureColorChannel(Led.ColorChannel.GREEN)); ledModule.play(true); } }); view.findViewById(R.id.led_blue_on).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { configureChannel(ledModule.configureColorChannel(Led.ColorChannel.BLUE)); ledModule.play(true); } }); view.findViewById(R.id.led_stop).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ledModule.stop(true); } }); view.findViewById(R.id.board_rssi_text).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mwBoard.readRssi().onComplete(new AsyncOperation.CompletionHandler<Integer>() { @Override public void success(Integer result) { ((TextView) view.findViewById(R.id.board_rssi_value)) .setText(String.format("%d dBm", result)); } }); } }); view.findViewById(R.id.board_battery_level_text).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mwBoard.readBatteryLevel().onComplete(new AsyncOperation.CompletionHandler<Byte>() { @Override public void success(Byte result) { ((TextView) view.findViewById(R.id.board_battery_level_value)) .setText(String.format("%d", result)); } @Override public void failure(Throwable error) { ((TextView) view.findViewById(R.id.board_battery_level_value)) .setText(R.string.label_sodium); } }); } }); view.findViewById(R.id.update_firmware).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { new AlertDialog.Builder(getActivity()).setTitle(R.string.title_firmware_update) .setPositiveButton(R.string.label_yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { initiateDfu(); } }).setNegativeButton(R.string.label_no, null).setCancelable(false) .setMessage(R.string.message_dfu_accept).show(); } }); }
From source file:com.anysoftkeyboard.keyboards.views.CandidateView.java
/** * Construct a CandidateView for showing suggested words for completion. *///from w w w.j a v a 2s . co m public CandidateView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); mSelectionHighlight = ContextCompat.getDrawable(context, R.drawable.list_selector_background_pressed); mAddToDictionaryHint = context.getString(R.string.hint_add_to_dictionary); // themed final KeyboardTheme theme = KeyboardThemeFactory.getCurrentKeyboardTheme(context.getApplicationContext()); TypedArray a = theme.getPackageContext().obtainStyledAttributes(attrs, R.styleable.AnyKeyboardViewTheme, 0, theme.getThemeResId()); int colorNormal = ContextCompat.getColor(context, R.color.candidate_normal); int colorRecommended = ContextCompat.getColor(context, R.color.candidate_recommended); int colorOther = ContextCompat.getColor(context, R.color.candidate_other); float fontSizePixel = context.getResources().getDimensionPixelSize(R.dimen.candidate_font_height); try { colorNormal = a.getColor(R.styleable.AnyKeyboardViewTheme_suggestionNormalTextColor, colorNormal); colorRecommended = a.getColor(R.styleable.AnyKeyboardViewTheme_suggestionRecommendedTextColor, colorRecommended); colorOther = a.getColor(R.styleable.AnyKeyboardViewTheme_suggestionOthersTextColor, colorOther); mDivider = a.getDrawable(R.styleable.AnyKeyboardViewTheme_suggestionDividerImage); final Drawable stripImage = a.getDrawable(R.styleable.AnyKeyboardViewTheme_suggestionBackgroundImage); if (stripImage == null) setBackgroundColor(Color.BLACK); else setBackgroundDrawable(stripImage); fontSizePixel = a.getDimension(R.styleable.AnyKeyboardViewTheme_suggestionTextSize, fontSizePixel); } catch (Exception e) { Logger.w(TAG, "Got an exception while reading theme data", e); } mHorizontalGap = a.getDimension(R.styleable.AnyKeyboardViewTheme_suggestionWordXGap, 20); a.recycle(); mColorNormal = colorNormal; mColorRecommended = colorRecommended; mColorOther = colorOther; if (mDivider == null) mDivider = ContextCompat.getDrawable(context, R.drawable.dark_suggestions_divider); // end of themed mPaint = new Paint(); mPaint.setColor(mColorNormal); mPaint.setAntiAlias(true); mPaint.setTextSize(fontSizePixel); mPaint.setStrokeWidth(0); mPaint.setTextAlign(Align.CENTER); mTextPaint = new TextPaint(mPaint); final int minTouchableWidth = context.getResources() .getDimensionPixelOffset(R.dimen.candidate_min_touchable_width); mGestureDetector = new GestureDetector(context, new CandidateStripGestureListener(minTouchableWidth)); setWillNotDraw(false); setHorizontalScrollBarEnabled(false); setVerticalScrollBarEnabled(false); scrollTo(0, getScrollY()); }
From source file:com.hippo.widget.Slider.java
@SuppressWarnings("deprecation") private void init(Context context, AttributeSet attrs) { mContext = context;// w ww . j av a 2s .co m mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); Paint textPaint = new Paint(Paint.ANTI_ALIAS_FLAG); textPaint.setTextAlign(Paint.Align.CENTER); Resources resources = context.getResources(); mBubbleMinWidth = resources.getDimensionPixelOffset(R.dimen.slider_bubble_width); mBubbleMinHeight = resources.getDimensionPixelOffset(R.dimen.slider_bubble_height); mBubble = new BubbleView(context, textPaint); mBubble.setScaleX(0.0f); mBubble.setScaleY(0.0f); AbsoluteLayout absoluteLayout = new AbsoluteLayout(context); absoluteLayout.addView(mBubble); absoluteLayout.setBackgroundDrawable(null); mPopup = new PopupWindow(absoluteLayout); mPopup.setOutsideTouchable(false); mPopup.setTouchable(false); mPopup.setFocusable(false); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Slider); textPaint.setColor(a.getColor(R.styleable.Slider_textColor, Color.WHITE)); textPaint.setTextSize(a.getDimensionPixelSize(R.styleable.Slider_textSize, 12)); updateTextSize(); setRange(a.getInteger(R.styleable.Slider_start, 0), a.getInteger(R.styleable.Slider_end, 0)); setProgress(a.getInteger(R.styleable.Slider_slider_progress, 0)); mThickness = a.getDimension(R.styleable.Slider_thickness, 2); mRadius = a.getDimension(R.styleable.Slider_radius, 6); setColor(a.getColor(R.styleable.Slider_color, Color.BLACK)); mBgPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mBgPaint.setColor(a.getBoolean(R.styleable.Slider_dark, false) ? 0x4dffffff : 0x42000000); a.recycle(); mProgressAnimation = new ValueAnimator(); mProgressAnimation.setInterpolator(AnimationUtils.FAST_SLOW_INTERPOLATOR); mProgressAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(@NonNull ValueAnimator animation) { float value = (Float) animation.getAnimatedValue(); mDrawPercent = value; mDrawProgress = Math.round(MathUtils.lerp((float) mStart, mEnd, value)); updateBubblePosition(); mBubble.setProgress(mDrawProgress); invalidate(); } }); mBubbleScaleAnimation = new ValueAnimator(); mBubbleScaleAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(@NonNull ValueAnimator animation) { float value = (Float) animation.getAnimatedValue(); mDrawBubbleScale = value; mBubble.setScaleX(value); mBubble.setScaleY(value); invalidate(); } }); }
From source file:com.intel.xdk.device.Device.java
@Override public void initialize(CordovaInterface cordova, final CordovaWebView webView) { super.initialize(cordova, webView); this.activity = cordova.getActivity(); this.webView = webView; //remote site support remoteLayout = new AbsoluteLayout(activity); remoteLayout.setBackgroundColor(Color.BLACK); //hide the remote site display until needed remoteLayout.setVisibility(View.GONE); //create the close button remoteClose = new ImageButton(activity); remoteClose.setBackgroundColor(Color.TRANSPARENT); Drawable remoteCloseImage = null;/*from w ww .j av a 2 s. c o m*/ remoteCloseImage = activity.getResources().getDrawable( activity.getResources().getIdentifier("remote_close", "drawable", activity.getPackageName())); File remoteCloseImageFile = new File(activity.getFilesDir(), "_intelxdk/remote_close.png"); if (remoteCloseImageFile.exists()) { remoteCloseImage = (Drawable.createFromPath(remoteCloseImageFile.getAbsolutePath())); } else { remoteCloseImage = (activity.getResources().getDrawable( activity.getResources().getIdentifier("remote_close", "drawable", activity.getPackageName()))); } //set the button image //remoteClose.setImageDrawable(remoteCloseImage); remoteClose.setBackgroundDrawable(remoteCloseImage); //set up the button click action remoteClose.setOnClickListener(new OnClickListener() { public void onClick(View v) { closeRemoteSite(); } }); //add the close button remoteLayout.addView(remoteClose); final ViewGroup parent = (ViewGroup) webView.getEngine().getView().getParent(); activity.runOnUiThread(new Runnable() { public void run() { if (parent != null) { //add layout to activity root layout parent.addView(remoteLayout, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, Gravity.CENTER)); } } }); //Initialize the orientation. lastOrientation = "unknown"; //Listen to the orientation change. OrientationEventListener listener = new OrientationEventListener(activity) { @Override public void onOrientationChanged(int orientation) { //Log.d("orientation","orientation: " + orientation); String currentOrientation = "unknown"; boolean orientationChanged = false; //int displayOrientation = 0; if (orientation > 345 || orientation < 15) { currentOrientation = "portrait"; displayOrientation = 0; } else if (orientation > 75 && orientation < 105) { currentOrientation = "landscape"; displayOrientation = 90; } else if (orientation > 165 && orientation < 195) { currentOrientation = "portrait"; displayOrientation = 180; } else if (orientation > 255 && orientation < 285) { currentOrientation = "landscape"; displayOrientation = -90; } if (currentOrientation.equals("unknown")) { currentOrientation = lastOrientation; } if (!currentOrientation.equals(lastOrientation)) { orientationChanged = true; Log.d("orientation", "Orientation changes from " + lastOrientation + " to " + currentOrientation + ", current orientation: " + orientation + "."); } if (orientationChanged) { String js = "javascript:try{intel.xdk.device.orientation='" + displayOrientation + "';}catch(e){}var e = document.createEvent('Events');e.initEvent('intel.xdk.device.orientation.change', true, true);e.success=true;e.orientation='" + displayOrientation + "';document.dispatchEvent(e);"; injectJS(js); } lastOrientation = currentOrientation; } }; listener.enable(); registerScreenStatusReceiver(); //cache references to methods for use in injectJS try { evaluateJavascript = webView.getClass().getMethod("evaluateJavascript", String.class, ValueCallback.class); } catch (Exception e) { } try { sendJavascript = webView.getClass().getMethod("sendJavascript", String.class); } catch (Exception e) { } emptyVC = new ValueCallback<String>() { @Override public void onReceiveValue(String s) { } }; }
From source file:com.coincollection.ReorderCollections.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); // If the screen rotated and our view got destroyed/recreated, // grab the list of collections from the old view (that we stored // in the bundle.) if (savedInstanceState != null) { mItems = savedInstanceState.getParcelableArrayList("mItems"); mUnsavedChanges = savedInstanceState.getBoolean("mUnsavedChanges"); }/*from w ww. j av a2s. co m*/ RecyclerView mRecyclerView = (RecyclerView) view.findViewById(R.id.reorder_collections_recycler_view); mRecyclerView.setBackgroundColor(Color.BLACK); // Indicate that the contents do not change the layout size of the RecyclerView mRecyclerView.setHasFixedSize(true); // Use a linear layout manager RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getActivity()); mRecyclerView.setLayoutManager(mLayoutManager); // Set up the adapter that provides the collection entries ReorderAdapter mAdapter = new ReorderAdapter(mItems, this); mRecyclerView.setAdapter(mAdapter); // Register the ItemTouchHelper Callback so that we can allow reordering // collections when the user drags the coin images or long presses and then // drags. ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(mAdapter); mItemTouchHelper = new ItemTouchHelper(callback); mItemTouchHelper.attachToRecyclerView(mRecyclerView); // Register a callback so we can know when the list has been reordered mAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() { @Override public void onItemRangeMoved(int fromPosition, int toPosition, int itemCount) { super.onItemRangeMoved(fromPosition, toPosition, itemCount); Log.d("onItemRangeMoved", String.valueOf(fromPosition) + " " + String.valueOf(toPosition) + " " + String.valueOf(itemCount)); ReorderCollections fragment = (ReorderCollections) getFragmentManager() .findFragmentByTag("ReorderFragment"); fragment.setUnsavedChanges(true); fragment.showUnsavedTextView(); } }); if (mUnsavedChanges) { showUnsavedTextView(); } //http://stackoverflow.com/questions/7992216/android-fragment-handle-back-button-press view.setFocusableInTouchMode(true); view.requestFocus(); view.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) { if (mUnsavedChanges) { showUnsavedChangesMessage(); } else { closeFragment(); } return true; } return false; } }); }
From source file:com.metinkale.prayerapp.vakit.PrefsView.java
@Override public void draw(Canvas canvas) { super.draw(canvas); canvas.scale(0.8f, 0.8f, canvas.getWidth() / 2, canvas.getHeight() / 2); Object o = getValue();/*from w ww. j av a 2s . c om*/ boolean active = ((o instanceof Boolean) && o.equals(true)) || ((o instanceof Integer) && !o.equals(0)) || ((o instanceof String) && !((String) o).startsWith("silent")); if (mPref == Pref.Vibration2) { active = !o.equals(-1); } mPaint.setColor(active ? 0xff03A9F4 : 0xffe0e0e0); int w = getHeight(); canvas.drawCircle(w / 2, w / 2, w / 2, mPaint); int p = w / 7; mDrawable.setBounds(p, p, w - p, w - p); mDrawable.setColorFilter(active ? sCFActive : sCFInactive); mDrawable.draw(canvas); if ((mPref == Pref.Time) || (mPref == Pref.SabahTime) || (mPref == Pref.Silenter)) { int s = (Integer) getValue(); if (s != 0) { mPaint.setColor(getResources().getColor(R.color.colorPrimaryDark)); canvas.drawCircle(getWidth() * 0.78f, getHeight() * 0.78f, getWidth() / 4, mPaint); mPaint.setColor(Color.WHITE); mPaint.setTextAlign(Align.CENTER); mPaint.setTextSize(w / 5); mPaint.setTypeface(Typeface.DEFAULT_BOLD); canvas.drawText(s + "", w * 0.78f, w * 0.87f, mPaint); } } else if (mPref == Pref.Vibration2) { int s = (Integer) getValue(); String txt = ""; if (s == 0) { txt = "8"; } else if (s == 1) { txt = "1"; } mPaint.setColor(Color.BLACK); mPaint.setTextAlign(Align.CENTER); mPaint.setTextSize(w / 2); mPaint.setTypeface(Typeface.DEFAULT_BOLD); if (s == 0) { canvas.rotate(90, canvas.getWidth() / 2, canvas.getHeight() / 2); canvas.drawText(txt, w / 2, (w * 2) / 3, mPaint); canvas.rotate(-90, canvas.getWidth() / 2, canvas.getHeight() / 2); } else { canvas.drawText(txt, w / 2, w * 2 / 3, mPaint); } } }