List of usage examples for android.support.v4.content ContextCompat getDrawable
public static final Drawable getDrawable(Context context, int i)
From source file:com.google.firebase.codelab.friendlychat.ChatFragment.java
public void onStart() { super.onStart(); mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this.getActivity()); mUsername = ANONYMOUS;//w w w. j a v a 2 s . c om // Initialize Firebase Auth mFirebaseAuth = FirebaseAuth.getInstance(); mFirebaseUser = mFirebaseAuth.getCurrentUser(); mUsername = mFirebaseUser.getDisplayName(); mPhotoUrl = mFirebaseUser.getPhotoUrl().toString(); mProgressBar = (ProgressBar) getView().findViewById(R.id.progressBar); mMessageRecyclerView = (RecyclerView) getView().findViewById(R.id.messageRecyclerView); mLinearLayoutManager = new LinearLayoutManager(getActivity()); mLinearLayoutManager.setStackFromEnd(true); mFirebaseDatabaseReference = FirebaseDatabase.getInstance().getReference(); mFirebaseAdapter = new FirebaseRecyclerAdapter<FriendlyMessage, MessageViewHolder>(FriendlyMessage.class, R.layout.item_message, MessageViewHolder.class, mFirebaseDatabaseReference.child(MESSAGES_CHILD)) { @Override protected FriendlyMessage parseSnapshot(DataSnapshot snapshot) { FriendlyMessage friendlyMessage = super.parseSnapshot(snapshot); if (friendlyMessage != null) { friendlyMessage.setId(snapshot.getKey()); } return friendlyMessage; } @Override protected void populateViewHolder(MessageViewHolder viewHolder, FriendlyMessage friendlyMessage, int position) { mProgressBar.setVisibility(ProgressBar.INVISIBLE); viewHolder.messageTextView.setText(friendlyMessage.getText()); viewHolder.messengerTextView.setText(friendlyMessage.getName()); if (friendlyMessage.getPhotoUrl() == null) { viewHolder.messengerImageView.setImageDrawable( ContextCompat.getDrawable(getActivity(), R.drawable.ic_account_circle_black_36dp)); } else { Glide.with(ChatFragment.this).load(friendlyMessage.getPhotoUrl()) .into(viewHolder.messengerImageView); } // write this message to the on-device index FirebaseAppIndex.getInstance().update(getMessageIndexable(friendlyMessage)); // log a view action on it FirebaseUserActions.getInstance().end(getMessageViewAction(friendlyMessage)); } }; mFirebaseAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() { @Override public void onItemRangeInserted(int positionStart, int itemCount) { super.onItemRangeInserted(positionStart, itemCount); int friendlyMessageCount = mFirebaseAdapter.getItemCount(); int lastVisiblePosition = mLinearLayoutManager.findLastCompletelyVisibleItemPosition(); // If the recycler view is initially being loaded or the user is at the bottom of the list, scroll // to the bottom of the list to show the newly added message. if (lastVisiblePosition == -1 || (positionStart >= (friendlyMessageCount - 1) && lastVisiblePosition == (positionStart - 1))) { mMessageRecyclerView.scrollToPosition(positionStart); } } }); mMessageRecyclerView.setLayoutManager(mLinearLayoutManager); mMessageRecyclerView.setAdapter(mFirebaseAdapter); // Initialize Firebase Measurement. mFirebaseAnalytics = FirebaseAnalytics.getInstance(getActivity()); // Initialize Firebase Remote Config. mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance(); // Define Firebase Remote Config Settings. FirebaseRemoteConfigSettings firebaseRemoteConfigSettings = new FirebaseRemoteConfigSettings.Builder() .setDeveloperModeEnabled(true).build(); // Define default config values. Defaults are used when fetched config values are not // available. Eg: if an error occurred fetching values from the server. Map<String, Object> defaultConfigMap = new HashMap<>(); defaultConfigMap.put("friendly_msg_length", 1000L); // Apply config settings and default values. mFirebaseRemoteConfig.setConfigSettings(firebaseRemoteConfigSettings); mFirebaseRemoteConfig.setDefaults(defaultConfigMap); // Fetch remote config. fetchConfig(); mMessageEditText = (EditText) getView().findViewById(R.id.messageEditText); mMessageEditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter( mSharedPreferences.getInt(CodelabPreferences.FRIENDLY_MSG_LENGTH, DEFAULT_MSG_LENGTH_LIMIT)) }); mMessageEditText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { if (charSequence.toString().trim().length() > 0) { mSendButton.setEnabled(true); } else { mSendButton.setEnabled(false); } } @Override public void afterTextChanged(Editable editable) { } }); mSendButton = (Button) getView().findViewById(R.id.sendButton); mSendButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { FriendlyMessage friendlyMessage = new FriendlyMessage(mMessageEditText.getText().toString(), mUsername, mPhotoUrl); mFirebaseDatabaseReference.child(MESSAGES_CHILD).push().setValue(friendlyMessage); mMessageEditText.setText(""); mFirebaseAnalytics.logEvent(MESSAGE_SENT_EVENT, null); } }); }
From source file:com.github.takahirom.plaidanimation.transition.FabTransform.java
@Override public Animator createAnimator(final ViewGroup sceneRoot, final TransitionValues startValues, final TransitionValues endValues) { if (startValues == null || endValues == null) return null; final Rect startBounds = (Rect) startValues.values.get(PROP_BOUNDS); final Rect endBounds = (Rect) endValues.values.get(PROP_BOUNDS); final boolean fromFab = endBounds.width() > startBounds.width(); final View view = endValues.view; final Rect dialogBounds = fromFab ? endBounds : startBounds; final Rect fabBounds = fromFab ? startBounds : endBounds; final Interpolator fastOutSlowInInterpolator = new FastOutSlowInInterpolator(); final long duration = getDuration(); final long halfDuration = duration / 2; final long twoThirdsDuration = duration * 2 / 3; if (!fromFab) { // Force measure / layout the dialog back to it's original bounds view.measure(makeMeasureSpec(startBounds.width(), View.MeasureSpec.EXACTLY), makeMeasureSpec(startBounds.height(), View.MeasureSpec.EXACTLY)); view.layout(startBounds.left, startBounds.top, startBounds.right, startBounds.bottom); }/* w ww .j av a 2s . com*/ final int translationX = startBounds.centerX() - endBounds.centerX(); final int translationY = startBounds.centerY() - endBounds.centerY(); if (fromFab) { view.setTranslationX(translationX); view.setTranslationY(translationY); } // Add a color overlay to fake appearance of the FAB final ColorDrawable fabColor = new ColorDrawable(color); fabColor.setBounds(0, 0, dialogBounds.width(), dialogBounds.height()); if (!fromFab) fabColor.setAlpha(0); view.getOverlay().add(fabColor); // Add an icon overlay again to fake the appearance of the FAB final Drawable fabIcon = ContextCompat.getDrawable(sceneRoot.getContext(), icon).mutate(); final int iconLeft = (dialogBounds.width() - fabIcon.getIntrinsicWidth()) / 2; final int iconTop = (dialogBounds.height() - fabIcon.getIntrinsicHeight()) / 2; fabIcon.setBounds(iconLeft, iconTop, iconLeft + fabIcon.getIntrinsicWidth(), iconTop + fabIcon.getIntrinsicHeight()); if (!fromFab) fabIcon.setAlpha(0); view.getOverlay().add(fabIcon); // Circular clip from/to the FAB size final Animator circularReveal; if (fromFab) { circularReveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2, view.getHeight() / 2, startBounds.width() / 2, (float) Math.hypot(endBounds.width() / 2, endBounds.height() / 2)); circularReveal.setInterpolator(new FastOutLinearInInterpolator()); } else { circularReveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2, view.getHeight() / 2, (float) Math.hypot(startBounds.width() / 2, startBounds.height() / 2), endBounds.width() / 2); circularReveal.setInterpolator(new LinearOutSlowInInterpolator()); // Persist the end clip i.e. stay at FAB size after the reveal has run circularReveal.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { view.setOutlineProvider(new ViewOutlineProvider() { @Override public void getOutline(View view, Outline outline) { final int left = (view.getWidth() - fabBounds.width()) / 2; final int top = (view.getHeight() - fabBounds.height()) / 2; outline.setOval(left, top, left + fabBounds.width(), top + fabBounds.height()); view.setClipToOutline(true); } }); } }); } circularReveal.setDuration(duration); // Translate to end position along an arc final Animator translate = ObjectAnimator.ofFloat(view, View.TRANSLATION_X, View.TRANSLATION_Y, fromFab ? getPathMotion().getPath(translationX, translationY, 0, 0) : getPathMotion().getPath(0, 0, -translationX, -translationY)); translate.setDuration(duration); translate.setInterpolator(fastOutSlowInInterpolator); // Fade contents of non-FAB view in/out List<Animator> fadeContents = null; if (view instanceof ViewGroup) { final ViewGroup vg = ((ViewGroup) view); fadeContents = new ArrayList<>(vg.getChildCount()); for (int i = vg.getChildCount() - 1; i >= 0; i--) { final View child = vg.getChildAt(i); final Animator fade = ObjectAnimator.ofFloat(child, View.ALPHA, fromFab ? 1f : 0f); if (fromFab) { child.setAlpha(0f); } fade.setDuration(twoThirdsDuration); fade.setInterpolator(fastOutSlowInInterpolator); fadeContents.add(fade); } } // Fade in/out the fab color & icon overlays final Animator colorFade = ObjectAnimator.ofInt(fabColor, "alpha", fromFab ? 0 : 255); final Animator iconFade = ObjectAnimator.ofInt(fabIcon, "alpha", fromFab ? 0 : 255); if (!fromFab) { colorFade.setStartDelay(halfDuration); iconFade.setStartDelay(halfDuration); } colorFade.setDuration(halfDuration); iconFade.setDuration(halfDuration); colorFade.setInterpolator(fastOutSlowInInterpolator); iconFade.setInterpolator(fastOutSlowInInterpolator); // Work around issue with elevation shadows. At the end of the return transition the shared // element's shadow is drawn twice (by each activity) which is jarring. This workaround // still causes the shadow to snap, but it's better than seeing it double drawn. Animator elevation = null; if (!fromFab) { elevation = ObjectAnimator.ofFloat(view, View.TRANSLATION_Z, -view.getElevation()); elevation.setDuration(duration); elevation.setInterpolator(fastOutSlowInInterpolator); } // Run all animations together final AnimatorSet transition = new AnimatorSet(); transition.playTogether(circularReveal, translate, colorFade, iconFade); transition.playTogether(fadeContents); if (elevation != null) transition.play(elevation); if (fromFab) { transition.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { // Clean up view.getOverlay().clear(); } }); } return new AnimUtils.NoPauseAnimator(transition); }
From source file:com.cgopir.trackme.chat.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); mUsername = ANONYMOUS;//from w ww .j ava 2 s. c o m // Initialize Firebase Auth mFirebaseAuth = FirebaseAuth.getInstance(); mFirebaseUser = mFirebaseAuth.getCurrentUser(); if (mFirebaseUser == null) { // Not signed in, launch the Sign In activity startActivity(new Intent(this, SignInActivity.class)); finish(); return; } else { mUsername = mFirebaseUser.getDisplayName(); if (mFirebaseUser.getPhotoUrl() != null) { mPhotoUrl = mFirebaseUser.getPhotoUrl().toString(); } } mGoogleApiClient = new GoogleApiClient.Builder(this) .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */) .addApi(Auth.GOOGLE_SIGN_IN_API).build(); mProgressBar = (ProgressBar) findViewById(R.id.progressBar); mMessageRecyclerView = (RecyclerView) findViewById(R.id.messageRecyclerView); mLinearLayoutManager = new LinearLayoutManager(this); mLinearLayoutManager.setStackFromEnd(true); mFirebaseDatabaseReference = FirebaseDatabase.getInstance().getReference(); mFirebaseAdapter = new FirebaseRecyclerAdapter<FriendlyMessage, MessageViewHolder>(FriendlyMessage.class, R.layout.item_message, MessageViewHolder.class, mFirebaseDatabaseReference.child(MESSAGES_CHILD)) { @Override protected FriendlyMessage parseSnapshot(DataSnapshot snapshot) { FriendlyMessage friendlyMessage = super.parseSnapshot(snapshot); if (friendlyMessage != null) { friendlyMessage.setId(snapshot.getKey()); } return friendlyMessage; } @Override protected void populateViewHolder(MessageViewHolder viewHolder, FriendlyMessage friendlyMessage, int position) { mProgressBar.setVisibility(ProgressBar.INVISIBLE); viewHolder.messageTextView.setText(friendlyMessage.getText()); viewHolder.messengerTextView.setText(friendlyMessage.getName()); if (friendlyMessage.getPhotoUrl() == null) { viewHolder.messengerImageView.setImageDrawable( ContextCompat.getDrawable(MainActivity.this, R.drawable.ic_account_circle_black_36dp)); } else { Glide.with(MainActivity.this).load(friendlyMessage.getPhotoUrl()) .into(viewHolder.messengerImageView); } // write this message to the on-device index FirebaseAppIndex.getInstance().update(getMessageIndexable(friendlyMessage)); // log a view action on it FirebaseUserActions.getInstance().end(getMessageViewAction(friendlyMessage)); } }; mFirebaseAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() { @Override public void onItemRangeInserted(int positionStart, int itemCount) { super.onItemRangeInserted(positionStart, itemCount); int friendlyMessageCount = mFirebaseAdapter.getItemCount(); int lastVisiblePosition = mLinearLayoutManager.findLastCompletelyVisibleItemPosition(); // If the recycler view is initially being loaded or the user is at the bottom of the list, scroll // to the bottom of the list to show the newly added message. if (lastVisiblePosition == -1 || (positionStart >= (friendlyMessageCount - 1) && lastVisiblePosition == (positionStart - 1))) { mMessageRecyclerView.scrollToPosition(positionStart); } } }); mMessageRecyclerView.setLayoutManager(mLinearLayoutManager); mMessageRecyclerView.setAdapter(mFirebaseAdapter); // Initialize and request AdMob ad. //mAdView = (AdView) findViewById(R.id.adView); //AdRequest adRequest = new AdRequest.Builder().build(); //mAdView.loadAd(adRequest); // Initialize Firebase Measurement. mFirebaseAnalytics = FirebaseAnalytics.getInstance(this); // Initialize Firebase Remote Config. mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance(); // Define Firebase Remote Config Settings. FirebaseRemoteConfigSettings firebaseRemoteConfigSettings = new FirebaseRemoteConfigSettings.Builder() .setDeveloperModeEnabled(true).build(); // Define default config values. Defaults are used when fetched config values are not // available. Eg: if an error occurred fetching values from the server. Map<String, Object> defaultConfigMap = new HashMap<>(); defaultConfigMap.put("friendly_msg_length", 10L); // Apply config settings and default values. mFirebaseRemoteConfig.setConfigSettings(firebaseRemoteConfigSettings); mFirebaseRemoteConfig.setDefaults(defaultConfigMap); // Fetch remote config. fetchConfig(); mMessageEditText = (EditText) findViewById(R.id.messageEditText); mMessageEditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter( mSharedPreferences.getInt(CodelabPreferences.FRIENDLY_MSG_LENGTH, DEFAULT_MSG_LENGTH_LIMIT)) }); mMessageEditText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { if (charSequence.toString().trim().length() > 0) { mSendButton.setEnabled(true); } else { mSendButton.setEnabled(false); } } @Override public void afterTextChanged(Editable editable) { } }); mSendButton = (Button) findViewById(R.id.sendButton); mSendButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { FriendlyMessage friendlyMessage = new FriendlyMessage(mMessageEditText.getText().toString(), mUsername, mPhotoUrl); mFirebaseDatabaseReference.child(MESSAGES_CHILD).push().setValue(friendlyMessage); mMessageEditText.setText(""); mFirebaseAnalytics.logEvent(MESSAGE_SENT_EVENT, null); } }); }
From source file:com.bt.heliniumstudentapp.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mainContext = this; HeliniumStudentApp.setLocale(this); if (!isOnline() && PreferenceManager.getDefaultSharedPreferences(this).getString("schedule_0", null) == null) { //TODO Keep app running and display empty ScheduleFragment with retry option Toast.makeText(this, getResources().getString(R.string.error_conn_no) + ". " + getResources().getString(R.string.database_no) + ".", Toast.LENGTH_LONG).show(); finish();//from ww w .j av a2 s . c o m } else if ((PreferenceManager.getDefaultSharedPreferences(this).getString("username", null) == null || PreferenceManager.getDefaultSharedPreferences(this).getString("password", null) == null) && PreferenceManager.getDefaultSharedPreferences(this).getString("schedule_0", null) == null) { startActivity(new Intent(this, LoginActivity.class)); finish(); } else { setContentView(R.layout.activity_main); toolbarTB = (Toolbar) findViewById(R.id.tb_toolbar_am); drawerDL = (DrawerLayout) findViewById(R.id.dl_drawer_am); drawerNV = (NavigationView) findViewById(R.id.nv_drawer_am); containerFL = findViewById(R.id.fl_container_am); containerLL = findViewById(R.id.ll_container_am); statusLL = findViewById(R.id.ll_status_am); weekTV = (TextView) findViewById(R.id.tv_week_am); yearTV = (TextView) findViewById(R.id.tv_year_am); prevIV = (ImageView) findViewById(R.id.iv_prev_am); historyIV = (ImageView) findViewById(R.id.iv_select_am); nextIV = (ImageView) findViewById(R.id.iv_next_am); setColors( Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(this) .getString("pref_customization_theme", "0")), Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(this) .getString("pref_customization_color_primary", "4")), Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(this) .getString("pref_customization_color_accent", "14"))); setSupportActionBar(toolbarTB); toolbarTB.setBackgroundColor(ContextCompat.getColor(this, primaryColor)); drawerDLtoggle = new ActionBarDrawerToggle(this, drawerDL, toolbarTB, 0, 0); drawerDLtoggle.setDrawerIndicatorEnabled(false); Drawable navigationIcon = ContextCompat.getDrawable(this, R.drawable.ic_menu); navigationIcon.setColorFilter(ContextCompat.getColor(this, primaryTextColor), PorterDuff.Mode.SRC_ATOP); drawerDLtoggle.setHomeAsUpIndicator(navigationIcon); drawerDLtoggle.setToolbarNavigationClickListener(new View.OnClickListener() { @Override public void onClick(View v) { drawerDL.openDrawer(drawerNV); } }); drawerDLtoggle.syncState(); ((ProgressBar) findViewById(R.id.pb_progressbar_am)).getIndeterminateDrawable().setColorFilter( ContextCompat.getColor(this, accentPrimaryColor), android.graphics.PorterDuff.Mode.MULTIPLY); weekTV.setTextColor(ContextCompat.getColor(this, primaryTextColor)); yearTV.setTextColor(ContextCompat.getColor(this, secondaryTextColor)); prevIV.setColorFilter(ContextCompat.getColor(this, primaryTextColor)); historyIV.setColorFilter(ContextCompat.getColor(this, accentTextColor)); nextIV.setColorFilter(ContextCompat.getColor(this, primaryTextColor)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (themeColor == R.color.theme_dark) getWindow().setStatusBarColor(ContextCompat.getColor(this, themeColor)); else getWindow().setStatusBarColor(ContextCompat.getColor(this, themeDisabledTextColor)); setTaskDescription(new ActivityManager.TaskDescription(getResources().getString(R.string.app_name), BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher), ContextCompat.getColor(this, themeColor))); ((GradientDrawable) ((RippleDrawable) prevIV.getBackground()).getDrawable(0)) .setColor(ContextCompat.getColor(this, primaryColor)); //FIXME Improve this ridiculous workaround ((GradientDrawable) ((RippleDrawable) historyIV.getBackground()).getDrawable(0)) .setColor(ContextCompat.getColor(this, accentPrimaryColor)); ((GradientDrawable) ((RippleDrawable) nextIV.getBackground()).getDrawable(0)) .setColor(ContextCompat.getColor(this, primaryColor)); } else { ((GradientDrawable) prevIV.getBackground()).setColor(ContextCompat.getColor(this, primaryColor)); ((GradientDrawable) historyIV.getBackground()) .setColor(ContextCompat.getColor(this, accentPrimaryColor)); ((GradientDrawable) nextIV.getBackground()).setColor(ContextCompat.getColor(this, primaryColor)); } final ColorStateList drawerItemColorStateList = new ColorStateList( new int[][] { new int[] { android.R.attr.state_checked }, new int[] {} }, new int[] { ContextCompat.getColor(this, accentSecondaryColor), ContextCompat.getColor(this, themeSecondaryTextColor) }); FM = getSupportFragmentManager(); FM.beginTransaction().replace(R.id.fl_container_am, new ScheduleFragment(), "SCHEDULE").commit(); drawerDL.setBackgroundResource(themeColor); drawerNV.setBackgroundResource(themeColor); containerLL.setBackgroundResource(primaryColor); drawerNV.setItemIconTintList(drawerItemColorStateList); drawerNV.setItemTextColor(drawerItemColorStateList); drawerNV.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(@NonNull final MenuItem menuItem) { drawerDL.closeDrawers(); new Handler().postDelayed(new Runnable() { @Override public void run() { switch (menuItem.getItemId()) { case R.id.i_schedule_md: menuItem.setChecked(true); if (!FM.findFragmentById(R.id.fl_container_am).getTag().equals("SCHEDULE")) { weekTV.setText(""); yearTV.setText(""); prevIV.setOnClickListener(null); historyIV.setOnClickListener(null); nextIV.setOnClickListener(null); FM.beginTransaction() .replace(R.id.fl_container_am, new ScheduleFragment(), "SCHEDULE") .commit(); } break; case R.id.i_grades_md: menuItem.setChecked(true); if (!FM.findFragmentById(R.id.fl_container_am).getTag().equals("GRADES")) { weekTV.setText(""); yearTV.setText(""); prevIV.setOnClickListener(null); historyIV.setOnClickListener(null); nextIV.setOnClickListener(null); FM.beginTransaction() .replace(R.id.fl_container_am, new GradesFragment(), "GRADES").commit(); } break; case R.id.i_settings_md: startActivity(new Intent(mainContext, SettingsActivity.class)); break; case R.id.i_logout_md: if (isOnline()) { final AlertDialog.Builder logoutDialogBuilder = new AlertDialog.Builder( new ContextThemeWrapper(mainContext, themeDialog)); logoutDialogBuilder.setTitle(R.string.logout); logoutDialogBuilder.setMessage(R.string.logout_confirm); logoutDialogBuilder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { ScheduleFragment.scheduleJson = null; GradesFragment.gradesHtml = null; PreferenceManager.getDefaultSharedPreferences(mainContext) .edit().putString("username", null).apply(); PreferenceManager.getDefaultSharedPreferences(mainContext) .edit().putString("password", null).apply(); PreferenceManager.getDefaultSharedPreferences(mainContext) .edit().putString("pref_general_class", "0").apply(); PreferenceManager.getDefaultSharedPreferences(mainContext) .edit().putString("schedule_0", null).apply(); PreferenceManager.getDefaultSharedPreferences(mainContext) .edit().putString("schedule_start_0", null).apply(); PreferenceManager.getDefaultSharedPreferences(mainContext) .edit().putString("pref_schedule_version_0", null) .apply(); PreferenceManager.getDefaultSharedPreferences(mainContext) .edit().putString("schedule_1", null).apply(); PreferenceManager.getDefaultSharedPreferences(mainContext) .edit().putString("schedule_start_1", null).apply(); PreferenceManager.getDefaultSharedPreferences(mainContext) .edit().putString("pref_schedule_version_1", null) .apply(); PreferenceManager.getDefaultSharedPreferences(mainContext) .edit().putString("html_grades", null).apply(); PreferenceManager.getDefaultSharedPreferences(mainContext) .edit().putString("pref_grades_version", null).apply(); new Handler().postDelayed(new Runnable() { @Override public void run() { finish(); startActivity( new Intent(mainContext, MainActivity.class)); } }, HeliniumStudentApp.DELAY_RESTART); } }); logoutDialogBuilder.setNegativeButton(android.R.string.no, null); final AlertDialog logoutDialog = logoutDialogBuilder.create(); logoutDialog.setCanceledOnTouchOutside(true); logoutDialog.show(); logoutDialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor( ContextCompat.getColor(mainContext, accentSecondaryColor)); logoutDialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor( ContextCompat.getColor(mainContext, accentSecondaryColor)); } else { Toast.makeText(mainContext, R.string.error_conn_no, Toast.LENGTH_SHORT).show(); } break; case R.id.i_about_md: final AlertDialog.Builder aboutDialogBuilder = new AlertDialog.Builder( new ContextThemeWrapper(mainContext, themeDialog)); aboutDialogBuilder.setTitle(R.string.about); aboutDialogBuilder.setMessage(getResources().getString(R.string.app_name) + "\n\nCopyright (C) 2016 Bastiaan Teeuwen <bastiaan.teeuwen170@gmail.com>\n\n" + "This program is free software; you can redistribute it and/or " + "modify it under the terms of the GNU General Public License " + "as published by the Free Software Foundation; version 2 " + "of the License, or (at your option) any later version.\n\n" + "This program is distributed in the hope that it will be useful, " + "but WITHOUT ANY WARRANTY; without even the implied warranty of " + "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the " + "GNU General Public License for more details.\n\n" + "You should have received a copy of the GNU General Public License " + "along with this program; if not, write to the Free Software " + "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA."); aboutDialogBuilder.setNeutralButton(R.string.website, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(HeliniumStudentApp.URL_WEBSITE))); } catch (ActivityNotFoundException e) { Toast.makeText(mainContext, "Couldn't find a browser", Toast.LENGTH_SHORT).show(); } } }); aboutDialogBuilder.setPositiveButton(R.string.github, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(HeliniumStudentApp.URL_GITHUB))); } catch (ActivityNotFoundException e) { Toast.makeText(mainContext, "Couldn't find a browser", Toast.LENGTH_SHORT).show(); } } }); aboutDialogBuilder.setNegativeButton(android.R.string.cancel, null); final AlertDialog aboutDialog = aboutDialogBuilder.create(); aboutDialog.setCanceledOnTouchOutside(true); aboutDialog.show(); ((TextView) aboutDialog.findViewById(android.R.id.message)).setTextSize(12); aboutDialog.getButton(AlertDialog.BUTTON_NEUTRAL) .setTextColor(ContextCompat.getColor(mainContext, accentSecondaryColor)); aboutDialog.getButton(AlertDialog.BUTTON_POSITIVE) .setTextColor(ContextCompat.getColor(mainContext, accentSecondaryColor)); aboutDialog.getButton(AlertDialog.BUTTON_NEGATIVE) .setTextColor(ContextCompat.getColor(mainContext, accentSecondaryColor)); break; } } }, HeliniumStudentApp.DELAY_DRAWER); return true; } }); } }
From source file:com.jun.elephant.ui.main.MainActivity.java
private void initToolbar() { mToolBar.inflateMenu(R.menu.menu_main); Resources.Theme theme = getTheme(); TypedValue navIcon = new TypedValue(); TypedValue overFlowIcon = new TypedValue(); theme.resolveAttribute(R.attr.navIcon, navIcon, true); theme.resolveAttribute(R.attr.overFlowIcon, overFlowIcon, true); mToolBar.setNavigationIcon(navIcon.resourceId); mToolBar.setOverflowIcon(ContextCompat.getDrawable(this, overFlowIcon.resourceId)); }
From source file:com.hannesdorfmann.search.SearchActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_search); setRetainInstance(true);/*from w ww .j a v a 2 s . co m*/ ButterKnife.bind(this); setupSearchView(); auto = TransitionInflater.from(this).inflateTransition(R.transition.auto); adapter = new FeedAdapter(this, columns, PocketUtils.isPocketInstalled(this)); results.setAdapter(adapter); GridLayoutManager layoutManager = new GridLayoutManager(this, columns); layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { return adapter.getItemColumnSpan(position); } }); results.setLayoutManager(layoutManager); results.addOnScrollListener(new InfiniteScrollListener(layoutManager) { @Override public void onLoadMore() { if (!adapter.isLoadingMore()) { presenter.searchMore(searchView.getQuery().toString()); } } }); results.setHasFixedSize(true); results.addOnScrollListener(gridScroll); // extract the search icon's location passed from the launching activity, minus 4dp to // compensate for different paddings in the views searchBackDistanceX = getIntent().getIntExtra(EXTRA_MENU_LEFT, 0) - (int) TypedValue .applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, getResources().getDisplayMetrics()); searchIconCenterX = getIntent().getIntExtra(EXTRA_MENU_CENTER_X, 0); // translate icon to match the launching screen then animate back into position searchBackContainer.setTranslationX(searchBackDistanceX); searchBackContainer.animate().translationX(0f).setDuration(650L) .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.fast_out_slow_in)); // transform from search icon to back icon AnimatedVectorDrawable searchToBack = (AnimatedVectorDrawable) ContextCompat.getDrawable(this, R.drawable.avd_search_to_back); searchBack.setImageDrawable(searchToBack); searchToBack.start(); // for some reason the animation doesn't always finish (leaving a part arrow!?) so after // the animation set a static drawable. Also animation callbacks weren't added until API23 // so using post delayed :( // TODO fix properly!! searchBack.postDelayed(new Runnable() { @Override public void run() { searchBack.setImageDrawable( ContextCompat.getDrawable(SearchActivity.this, R.drawable.ic_arrow_back_padded)); } }, 600); // fade in the other search chrome searchBackground.animate().alpha(1f).setDuration(300L) .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.linear_out_slow_in)); searchView.animate().alpha(1f).setStartDelay(400L).setDuration(400L) .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.linear_out_slow_in)) .setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { searchView.requestFocus(); ImeUtils.showIme(searchView); } }); // animate in a scrim over the content behind scrim.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { scrim.getViewTreeObserver().removeOnPreDrawListener(this); AnimatorSet showScrim = new AnimatorSet(); showScrim.playTogether( ViewAnimationUtils.createCircularReveal(scrim, searchIconCenterX, searchBackground.getBottom(), 0, (float) Math.hypot(searchBackDistanceX, scrim.getHeight() - searchBackground.getBottom())), ObjectAnimator.ofArgb(scrim, ViewUtils.BACKGROUND_COLOR, Color.TRANSPARENT, ContextCompat.getColor(SearchActivity.this, R.color.scrim))); showScrim.setDuration(400L); showScrim.setInterpolator(AnimationUtils.loadInterpolator(SearchActivity.this, android.R.interpolator.linear_out_slow_in)); showScrim.start(); return false; } }); onNewIntent(getIntent()); }
From source file:com.hookedonplay.decoviewsample.SamplePeopleFragment.java
private void addAnimation(final DecoView arcView, int series, float moveTo, int delay, final ImageView imageView, final int imageId, final int color) { DecoEvent.ExecuteEventListener listener = new DecoEvent.ExecuteEventListener() { @Override/*from w w w . j a va 2s. c om*/ public void onEventStart(DecoEvent event) { imageView.setImageDrawable(ContextCompat.getDrawable(getActivity(), imageId)); showAvatar(true, imageView); arcView.addEvent(new DecoEvent.Builder(EventType.EVENT_COLOR_CHANGE, color).setIndex(mBack1Index) .setDuration(2000).build()); } @Override public void onEventEnd(DecoEvent event) { showAvatar(false, imageView); arcView.addEvent(new DecoEvent.Builder(EventType.EVENT_COLOR_CHANGE, COLOR_BACK) .setIndex(mBack1Index).setDuration(2000).build()); } }; arcView.addEvent(new DecoEvent.Builder(moveTo).setIndex(series).setDelay(delay).setDuration(5000) .setListener(listener).build()); }
From source file:com.example.cassi.hal.adapter.CardPresenter.java
private void getMovieTMDBdetail(final ImageCardView cardView, final T411TorrentItem item, Category category) { try {/*from www . j a v a 2 s . c o m*/ TmdbResult result = null; Call<TmdbResult> call = null; if (category == Category.MOVIE) { call = RetrofitManager.getInstance() .getRetrofitService(mContext.getString(R.string.themoviedb_api_base_url)) .getTMDBMovieByTitle(RegexUtils.getCleanedTorrentName(item.getName()), "fr", mContext.getString(R.string.themoviedb_key)); } else if (category == Category.TV) { call = RetrofitManager.getInstance() .getRetrofitService(mContext.getString(R.string.themoviedb_api_base_url)) .getTMDBSerieByTitle(RegexUtils.getCleanedTorrentName(item.getName()), "fr", mContext.getString(R.string.themoviedb_key)); } assert call != null; call.enqueue(new Callback<TmdbResult>() { @Override public void onResponse(Response<TmdbResult> response, Retrofit retrofit) { if (response.body().getResults() != null && response.body().getResults().size() > 0 && cardView.getTitleText().equals(item.getName())) { Glide.with(mContext) .load(mContext.getString(R.string.themoviedb_poster_url) + response.body().getResults().get(0).getPosterPath()) .error(ContextCompat.getDrawable(mContext, R.drawable.poster_placeholder)) .placeholder(ContextCompat.getDrawable(mContext, R.drawable.poster_placeholder)) .into(cardView.getMainImageView()); item.setBackgroundUrl(response.body().getResults().get(0).getBackdropPath()); item.setPosterUrl(response.body().getResults().get(0).getPosterPath()); } } @Override public void onFailure(Throwable t) { } }); } catch (Exception e) { e.printStackTrace(); } }
From source file:cn.djangoogle.pull2load.internal.LoadingLayout.java
public LoadingLayout(Context context, final Mode mode, final Orientation scrollDirection, TypedArray attrs) { super(context); mMode = mode;//from w w w . ja va 2 s. co m mScrollDirection = scrollDirection; switch (scrollDirection) { case HORIZONTAL: LayoutInflater.from(context).inflate(R.layout.pull2load_header_horizontal, this); break; case VERTICAL: default: LayoutInflater.from(context).inflate(R.layout.pull2load_header_vertical, this); break; } mInnerLayout = (FrameLayout) findViewById(R.id.fl_inner); mHeaderText = (TextView) mInnerLayout.findViewById(R.id.pull_to_refresh_text); mHeaderProgressWheel = (ProgressWheel) mInnerLayout.findViewById(R.id.pull_to_refresh_progress_wheel); mSubHeaderText = (TextView) mInnerLayout.findViewById(R.id.pull_to_refresh_sub_text); mHeaderImage = (ImageView) mInnerLayout.findViewById(R.id.pull_to_refresh_image); LayoutParams lp = (LayoutParams) mInnerLayout.getLayoutParams(); switch (mode) { case PULL_FROM_END: lp.gravity = scrollDirection == Orientation.VERTICAL ? Gravity.TOP : Gravity.LEFT; // Load in labels mPullLabel = context.getString(R.string.pull_to_refresh_from_bottom_pull_label); mRefreshingLabel = context.getString(R.string.pull_to_refresh_from_bottom_refreshing_label); mReleaseLabel = context.getString(R.string.pull_to_refresh_from_bottom_release_label); break; case PULL_FROM_START: default: lp.gravity = scrollDirection == Orientation.VERTICAL ? Gravity.BOTTOM : Gravity.RIGHT; // Load in labels mPullLabel = context.getString(R.string.pull_to_refresh_pull_label); mRefreshingLabel = context.getString(R.string.pull_to_refresh_refreshing_label); mReleaseLabel = context.getString(R.string.pull_to_refresh_release_label); break; } if (attrs.hasValue(R.styleable.PullToRefresh_ptrHeaderBackground)) { Drawable background = attrs.getDrawable(R.styleable.PullToRefresh_ptrHeaderBackground); if (null != background) { ViewCompat.setBackground(this, background); } } if (attrs.hasValue(R.styleable.PullToRefresh_ptrHeaderTextAppearance)) { TypedValue styleID = new TypedValue(); attrs.getValue(R.styleable.PullToRefresh_ptrHeaderTextAppearance, styleID); setTextAppearance(styleID.data); } if (attrs.hasValue(R.styleable.PullToRefresh_ptrSubHeaderTextAppearance)) { TypedValue styleID = new TypedValue(); attrs.getValue(R.styleable.PullToRefresh_ptrSubHeaderTextAppearance, styleID); setSubTextAppearance(styleID.data); } // Text Color attrs need to be set after TextAppearance attrs if (attrs.hasValue(R.styleable.PullToRefresh_ptrHeaderTextColor)) { ColorStateList colors = attrs.getColorStateList(R.styleable.PullToRefresh_ptrHeaderTextColor); if (null != colors) { setTextColor(colors); } } if (attrs.hasValue(R.styleable.PullToRefresh_ptrHeaderSubTextColor)) { ColorStateList colors = attrs.getColorStateList(R.styleable.PullToRefresh_ptrHeaderSubTextColor); if (null != colors) { setSubTextColor(colors); } } // Try and get defined drawable from Attrs Drawable imageDrawable = null; if (attrs.hasValue(R.styleable.PullToRefresh_ptrDrawable)) { imageDrawable = attrs.getDrawable(R.styleable.PullToRefresh_ptrDrawable); } // Check Specific Drawable from Attrs, these overrite the generic // drawable attr above switch (mode) { case PULL_FROM_START: default: if (attrs.hasValue(R.styleable.PullToRefresh_ptrDrawableStart)) { imageDrawable = attrs.getDrawable(R.styleable.PullToRefresh_ptrDrawableStart); } else if (attrs.hasValue(R.styleable.PullToRefresh_ptrDrawableTop)) { Pull2LoadCommonUtil.warnDeprecation("ptrDrawableTop", "ptrDrawableStart"); imageDrawable = attrs.getDrawable(R.styleable.PullToRefresh_ptrDrawableTop); } break; case PULL_FROM_END: if (attrs.hasValue(R.styleable.PullToRefresh_ptrDrawableEnd)) { imageDrawable = attrs.getDrawable(R.styleable.PullToRefresh_ptrDrawableEnd); } else if (attrs.hasValue(R.styleable.PullToRefresh_ptrDrawableBottom)) { Pull2LoadCommonUtil.warnDeprecation("ptrDrawableBottom", "ptrDrawableEnd"); imageDrawable = attrs.getDrawable(R.styleable.PullToRefresh_ptrDrawableBottom); } break; } // If we don't have a user defined drawable, load the default if (null == imageDrawable) { imageDrawable = ContextCompat.getDrawable(context, getDefaultDrawableResId()); } // Set Drawable, and save width/height setLoadingDrawable(imageDrawable); reset(); }
From source file:com.hellofyc.base.app.adapter.BaseRecyclerViewAdapter.java
@Override public Drawable getDrawable(@DrawableRes int id) { return ContextCompat.getDrawable(mContext, id); }