List of usage examples for android.app Activity findViewById
@Nullable public <T extends View> T findViewById(@IdRes int id)
From source file:dynamite.zafroshops.app.fragment.AllZopsFragment.java
private void setZops(boolean force) { Activity activity = getActivity(); adapter = new AllZopsGridViewAdapter(activity, R.id.gridItem, types); final SharedPreferences preferences = activity.getPreferences(0); final SharedPreferences.Editor editor = preferences.edit(); if (!preferences.contains(StorageKeys.ZOPCATEGORY_KEY)) { InputStream is = getResources().openRawResource(R.raw.zops); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); HashMap<String, MobileZop> temp = new HashMap<>(); types = new ArrayList<>( (ArrayList<MobileZop>) new Gson().fromJson(reader, new TypeToken<ArrayList<MobileZop>>() { }.getType()));// w w w. j a v a 2 s .com for (MobileZop type : types) { String key = type.Type.toString(); if (!temp.containsKey(key)) { temp.put(key, type); } } types = new ArrayList<>(temp.values()); if (adapter != null) { adapter.setObjects(types); adapter.notifyDataSetChanged(); } try { FileOutputStream fos = activity.openFileOutput(StorageKeys.ZOPCATEGORY_KEY, Context.MODE_PRIVATE); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(types); oos.close(); fos.close(); editor.putString(StorageKeys.ZOPCATEGORY_KEY, Integer.toString(types.size())); editor.commit(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } else { if (preferences.contains(StorageKeys.ZOPCATEGORY_KEY)) { try { FileInputStream fis = activity.openFileInput(StorageKeys.ZOPCATEGORY_KEY); ObjectInputStream ois = new ObjectInputStream(fis); types = (ArrayList) ois.readObject(); ois.close(); fis.close(); if (adapter != null) { adapter.setObjects(types); adapter.notifyDataSetChanged(); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (StreamCorruptedException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } } ListenableFuture<JsonElement> result = MainActivity.MobileClient.invokeApi("mobileZop", "GET", new ArrayList<Pair<String, String>>() { { add(new Pair<String, String>("count", "true")); } }); Futures.addCallback(result, new FutureCallback<JsonElement>() { @Override public void onSuccess(JsonElement result) { Activity activity = getActivity(); JsonArray typesAsJson = result.getAsJsonArray(); if (typesAsJson != null) { types = new Gson().fromJson(result, new TypeToken<ArrayList<MobileZop>>() { }.getType()); try { FileOutputStream fos = activity.openFileOutput(StorageKeys.ZOPCATEGORY_KEY, Context.MODE_PRIVATE); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(types); oos.close(); fos.close(); editor.putString(StorageKeys.ZOPCATEGORY_KEY, Integer.toString(types.size())); editor.commit(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } if (adapter != null) { adapter.setObjects(types); GridView zops = (GridView) activity.findViewById(R.id.gridViewZops); RelativeLayout loader = (RelativeLayout) activity.findViewById(R.id.relativeLayoutLoader); loader.setVisibility(View.INVISIBLE); zops.setVisibility(View.VISIBLE); adapter.notifyDataSetChanged(); } } @Override public void onFailure(@NonNull Throwable t) { Activity activity = getActivity(); if (activity != null && types.size() == 0) { GridView zops = (GridView) activity.findViewById(R.id.gridViewZops); RelativeLayout loader = (RelativeLayout) activity.findViewById(R.id.relativeLayoutLoader); zops.setVisibility(View.INVISIBLE); loader.setVisibility(View.VISIBLE); } } }); } }
From source file:carnero.cgeo.cgBase.java
public void showProgress(Activity activity, boolean status) { if (activity == null) { return;/*from ww w . j a v a 2 s . co m*/ } final ProgressBar progress = (ProgressBar) activity.findViewById(R.id.actionbar_progress); if (status == true) { progress.setVisibility(View.VISIBLE); } else { progress.setVisibility(View.GONE); } }
From source file:carnero.cgeo.cgBase.java
public void setTitle(Activity activity, String text) { if (activity == null || text == null) { return;/*from w w w. j av a 2 s . c om*/ } final TextView title = (TextView) activity.findViewById(R.id.actionbar_title); if (title != null) { title.setText(text); } }
From source file:com.android.tv.settings.dialog.old.BaseDialogFragment.java
public void performEntryTransition(final Activity activity, final ViewGroup contentView, int iconResourceId, Uri iconResourceUri, final ImageView icon, final TextView title, final TextView description, final TextView breadcrumb) { // Pull out the root layout of the dialog and set the background drawable, to be // faded in during the transition. final ViewGroup twoPane = (ViewGroup) contentView.getChildAt(0); twoPane.setVisibility(View.INVISIBLE); // If the appropriate data is embedded in the intent and there is an icon specified // in the content fragment, we animate the icon from its initial position to the final // position. Otherwise, we perform a simpler transition in which the ActionFragment // slides in and the ContentFragment text fields slide in. mIntroAnimationInProgress = true;//from w w w . j a v a2 s.co m List<TransitionImage> images = TransitionImage.readMultipleFromIntent(activity, activity.getIntent()); TransitionImageAnimation ltransitionAnimation = null; final Uri iconUri; final int color; if (images != null && images.size() > 0) { if (iconResourceId != 0) { iconUri = Uri.parse(UriUtils.getAndroidResourceUri(activity, iconResourceId)); } else if (iconResourceUri != null) { iconUri = iconResourceUri; } else { iconUri = null; } TransitionImage src = images.get(0); color = src.getBackground(); if (iconUri != null) { ltransitionAnimation = new TransitionImageAnimation(contentView); ltransitionAnimation.addTransitionSource(src); ltransitionAnimation.transitionDurationMs(ANIMATE_IN_DURATION).transitionStartDelayMs(0) .interpolator(new DecelerateInterpolator(1f)); } } else { iconUri = null; color = 0; } final TransitionImageAnimation transitionAnimation = ltransitionAnimation; // Fade out the old activity, and hard cut the new activity. activity.overridePendingTransition(R.anim.hard_cut_in, R.anim.fade_out); int bgColor = mFragment.getResources().getColor(R.color.dialog_activity_background); mBgDrawable.setColor(bgColor); mBgDrawable.setAlpha(0); twoPane.setBackground(mBgDrawable); // If we're animating the icon, we create a new ImageView in which to place the embedded // bitmap. We place it in the root layout to match its location in the previous activity. mShadowLayer = (FrameLayoutWithShadows) twoPane.findViewById(R.id.shadow_layout); if (transitionAnimation != null) { transitionAnimation.listener(new TransitionImageAnimation.Listener() { @Override public void onRemovedView(TransitionImage src, TransitionImage dst) { if (icon != null) { //want to make sure that users still see at least the source image // if the dst image is too large to finish downloading before the // animation is done. Check if the icon is not visible. This mean // BaseContentFragement have not finish downloading the image yet. if (icon.getVisibility() != View.VISIBLE) { icon.setImageDrawable(src.getBitmap()); int intrinsicWidth = icon.getDrawable().getIntrinsicWidth(); LayoutParams lp = icon.getLayoutParams(); lp.height = lp.width * icon.getDrawable().getIntrinsicHeight() / intrinsicWidth; icon.setVisibility(View.VISIBLE); } icon.setAlpha(1f); } if (mShadowLayer != null) { mShadowLayer.setShadowsAlpha(1f); } onIntroAnimationFinished(); } }); icon.setAlpha(0f); if (mShadowLayer != null) { mShadowLayer.setShadowsAlpha(0f); } } // We need to defer the remainder of the animation preparation until the first // layout has occurred, as we don't yet know the final location of the icon. twoPane.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { twoPane.getViewTreeObserver().removeOnGlobalLayoutListener(this); // if we buildLayer() at this time, the texture is actually not created // delay a little so we can make sure all hardware layer is created before // animation, in that way we can avoid the jittering of start animation twoPane.postOnAnimationDelayed(mEntryAnimationRunnable, ANIMATE_DELAY); } final Runnable mEntryAnimationRunnable = new Runnable() { @Override public void run() { if (!mFragment.isAdded()) { // We have been detached before this could run, so just bail return; } twoPane.setVisibility(View.VISIBLE); final int secondaryDelay = SLIDE_IN_DISTANCE; // Fade in the activity background protection ObjectAnimator oa = ObjectAnimator.ofInt(mBgDrawable, "alpha", 255); oa.setDuration(ANIMATE_IN_DURATION); oa.setStartDelay(secondaryDelay); oa.setInterpolator(new DecelerateInterpolator(1.0f)); oa.start(); View actionFragmentView = activity.findViewById(mActionAreaId); boolean isRtl = ViewCompat.getLayoutDirection(contentView) == ViewCompat.LAYOUT_DIRECTION_RTL; int startDist = isRtl ? SLIDE_IN_DISTANCE : -SLIDE_IN_DISTANCE; int endDist = isRtl ? -actionFragmentView.getMeasuredWidth() : actionFragmentView.getMeasuredWidth(); // Fade in and slide in the ContentFragment TextViews from the start. prepareAndAnimateView(title, 0, startDist, secondaryDelay, ANIMATE_IN_DURATION, new DecelerateInterpolator(1.0f), false); prepareAndAnimateView(breadcrumb, 0, startDist, secondaryDelay, ANIMATE_IN_DURATION, new DecelerateInterpolator(1.0f), false); prepareAndAnimateView(description, 0, startDist, secondaryDelay, ANIMATE_IN_DURATION, new DecelerateInterpolator(1.0f), false); // Fade in and slide in the ActionFragment from the end. prepareAndAnimateView(actionFragmentView, 0, endDist, secondaryDelay, ANIMATE_IN_DURATION, new DecelerateInterpolator(1.0f), false); if (icon != null && transitionAnimation != null) { // now we get the icon view in place, update the transition target TransitionImage target = new TransitionImage(); target.setUri(iconUri); target.createFromImageView(icon); if (icon.getBackground() instanceof ColorDrawable) { ColorDrawable d = (ColorDrawable) icon.getBackground(); target.setBackground(d.getColor()); } transitionAnimation.addTransitionTarget(target); transitionAnimation.startTransition(); } else if (icon != null) { prepareAndAnimateView(icon, 0, startDist, secondaryDelay, ANIMATE_IN_DURATION, new DecelerateInterpolator(1.0f), true /* is the icon */); if (mShadowLayer != null) { mShadowLayer.setShadowsAlpha(0f); } } } }; }); }
From source file:dynamite.zafroshops.app.fragment.TypedZopsFragment.java
private void setZops(final boolean force) { Activity activity = getActivity(); adapter = new TypedZopListViewAdapter(getActivity(), R.id.listViewItem, typedZops); final SharedPreferences preferences = activity.getPreferences(0); final SharedPreferences.Editor editor = preferences.edit(); final ZopType type = (ZopType) getArguments().get(ARG_ZOP_TYPE); final String key = StorageKeys.ZOPS_KEY + type.toString(); zopType = type;//from w w w .j a v a 2s . com if (!preferences.contains(key)) { InputStream is = getResources().openRawResource(R.raw.zops); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); typedZops = new ArrayList<>(Collections2.filter( (ArrayList<MobileZop>) new Gson().fromJson(reader, new TypeToken<ArrayList<MobileZop>>() { }.getType()), new Predicate<MobileZop>() { @Override public boolean apply(MobileZop input) { return input.Type == type && (!preferences.contains(StorageKeys.COUNTRY_KEY) || preferences.getString(StorageKeys.COUNTRY_KEY, "").equals("") || input.CountryID.equals(preferences.getString(StorageKeys.COUNTRY_KEY, ""))); } })); try { FileOutputStream fos = activity.openFileOutput(key, Context.MODE_PRIVATE); ObjectOutputStream oos = new ObjectOutputStream(fos); int count = typedZops.size(); oos.writeObject(typedZops); oos.close(); fos.close(); editor.putString(key, Integer.toString(count)); editor.commit(); setCount(count); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } else if (preferences.contains(key)) { try { FileInputStream fis = activity.openFileInput(key); ObjectInputStream ois = new ObjectInputStream(fis); ArrayList<MobileZop> temp = (ArrayList) ois.readObject(); typedZops = new ArrayList<>(Collections2.filter(temp, new Predicate<MobileZop>() { @Override public boolean apply(MobileZop input) { return input.Type == type && (!preferences.contains(StorageKeys.COUNTRY_KEY) || preferences.getString(StorageKeys.COUNTRY_KEY, "").equals("") || input.CountryID.equals(preferences.getString(StorageKeys.COUNTRY_KEY, ""))); } })); ois.close(); fis.close(); setCount(typedZops.size()); if (adapter != null) { adapter.setObjects(typedZops); adapter.notifyDataSetChanged(); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (StreamCorruptedException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } } if (force) { final ArrayList<Pair<String, String>> parameters; if (MainActivity.LastLocation != null) { parameters = new ArrayList<Pair<String, String>>() { { add(new Pair<>("latitude", Double.toString(MainActivity.LastLocation.Latitude))); add(new Pair<>("longitude", Double.toString(MainActivity.LastLocation.Longitude))); add(new Pair<>("type", type.getText())); } }; } else { parameters = new ArrayList<Pair<String, String>>() { { add(new Pair<>("type", type.getText())); } }; } ListenableFuture<JsonElement> result = MainActivity.MobileClient.invokeApi("mobileZop", "GET", parameters); Futures.addCallback(result, new FutureCallback<JsonElement>() { Activity activity = getActivity(); @Override public void onSuccess(JsonElement result) { JsonArray typesAsJson = result.getAsJsonArray(); if (typesAsJson != null) { ArrayList<MobileZop> temp = new Gson().fromJson(result, new TypeToken<ArrayList<MobileZop>>() { }.getType()); int max = Collections.max(temp, new Comparator<MobileZop>() { @Override public int compare(MobileZop lhs, MobileZop rhs) { if (lhs.DataVersion < rhs.DataVersion) { return -1; } else if (lhs.DataVersion > rhs.DataVersion) { return 1; } else { return 0; } } }).DataVersion; ((MainActivity) activity).Versions.put(zopType, max); try { FileOutputStream fos = activity.openFileOutput(key, Context.MODE_PRIVATE); ObjectOutputStream oos = new ObjectOutputStream(fos); int count = typedZops.size(); typedZops = new ArrayList<>(Collections2.filter(temp, new Predicate<MobileZop>() { @Override public boolean apply(MobileZop input) { return input.Type == type && (!preferences.contains(StorageKeys.COUNTRY_KEY) || preferences.getString(StorageKeys.COUNTRY_KEY, "").equals("") || input.CountryID .equals(preferences.getString(StorageKeys.COUNTRY_KEY, ""))); } })); oos.writeObject(typedZops); oos.close(); fos.close(); editor.putString(key, Integer.toString(count)); editor.commit(); setCount(count); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } if (adapter != null) { adapter.setObjects(typedZops); resetVisibility(false); adapter.notifyDataSetChanged(); } } @Override public void onFailure(@NonNull Throwable t) { ListView zops = (ListView) activity.findViewById(R.id.listViewZops); RelativeLayout loader = (RelativeLayout) activity.findViewById(R.id.relativeLayoutLoader); LinearLayout noZops = (LinearLayout) activity.findViewById(R.id.noZops); resetVisibility(zops, noZops, loader, false); } }); } }