List of usage examples for android.view View getResources
public Resources getResources()
From source file:android.support.car.app.CarFragmentActivity.java
private static String viewToString(View view) { StringBuilder out = new StringBuilder(128); out.append(view.getClass().getName()); out.append('{'); out.append(Integer.toHexString(System.identityHashCode(view))); out.append(' '); switch (view.getVisibility()) { case View.VISIBLE: out.append('V'); break;//from ww w . ja va 2 s.co m case View.INVISIBLE: out.append('I'); break; case View.GONE: out.append('G'); break; default: out.append('.'); break; } out.append(view.isFocusable() ? 'F' : '.'); out.append(view.isEnabled() ? 'E' : '.'); out.append(view.willNotDraw() ? '.' : 'D'); out.append(view.isHorizontalScrollBarEnabled() ? 'H' : '.'); out.append(view.isVerticalScrollBarEnabled() ? 'V' : '.'); out.append(view.isClickable() ? 'C' : '.'); out.append(view.isLongClickable() ? 'L' : '.'); out.append(' '); out.append(view.isFocused() ? 'F' : '.'); out.append(view.isSelected() ? 'S' : '.'); out.append(view.isPressed() ? 'P' : '.'); out.append(' '); out.append(view.getLeft()); out.append(','); out.append(view.getTop()); out.append('-'); out.append(view.getRight()); out.append(','); out.append(view.getBottom()); final int id = view.getId(); if (id != View.NO_ID) { out.append(" #"); out.append(Integer.toHexString(id)); final Resources r = view.getResources(); if (id != 0 && r != null) { try { String pkgname; switch (id & 0xff000000) { case 0x7f000000: pkgname = "app"; break; case 0x01000000: pkgname = "android"; break; default: pkgname = r.getResourcePackageName(id); break; } String typename = r.getResourceTypeName(id); String entryname = r.getResourceEntryName(id); out.append(" "); out.append(pkgname); out.append(":"); out.append(typename); out.append("/"); out.append(entryname); } catch (Resources.NotFoundException e) { } } } out.append("}"); return out.toString(); }
From source file:fiskinfoo.no.sintef.fiskinfoo.Implementation.UtilityOnClickListeners.java
@Override public OnClickListener getInformationDialogOnClickListener(final int titleId, final int messageId, final int iconId) { OnClickListener onClickListener;//from w ww . j a v a2 s . c om onClickListener = new OnClickListener() { @Override public void onClick(View v) { String message = v.getResources().getString(messageId); if (message.contains("href") || message.contains("www.")) { new UtilityDialogs().getHyperlinkAlertDialog(v.getContext(), titleId, messageId, iconId).show(); } else { new UtilityDialogs().getAlertDialog(v.getContext(), titleId, messageId, iconId).show(); } } }; return onClickListener; }
From source file:org.onebusaway.android.ui.ArrivalsListHeader.java
void initView(View view) { // Clear any existing arrival info mArrivalInfo = null;/*w ww. j ava 2 s . c om*/ mHeaderArrivalInfo.clear(); mNumHeaderArrivals = -1; // Cache the ArrivalsListHeader height values HEADER_HEIGHT_ONE_ARRIVAL_DP = view.getResources().getDimension(R.dimen.arrival_header_height_one_arrival) / view.getResources().getDisplayMetrics().density; HEADER_HEIGHT_TWO_ARRIVALS_DP = view.getResources().getDimension(R.dimen.arrival_header_height_two_arrivals) / view.getResources().getDisplayMetrics().density; HEADER_OFFSET_FILTER_ROUTES_DP = view.getResources() .getDimension(R.dimen.arrival_header_height_offset_filter_routes) / view.getResources().getDisplayMetrics().density; HEADER_HEIGHT_EDIT_NAME_DP = view.getResources().getDimension(R.dimen.arrival_header_height_edit_name) / view.getResources().getDisplayMetrics().density; // Init views mView = view; mMainContainerView = mView.findViewById(R.id.main_header_content); mNameContainerView = mView.findViewById(R.id.stop_name_and_info_container); mEditNameContainerView = mView.findViewById(R.id.edit_name_container); mNameView = (TextView) mView.findViewById(R.id.stop_name); mEditNameView = (EditText) mView.findViewById(R.id.edit_name); mStopFavorite = (ImageButton) mView.findViewById(R.id.stop_favorite); mStopFavorite.setColorFilter(mView.getResources().getColor(R.color.header_text_color)); mFilterGroup = mView.findViewById(R.id.filter_group); mShowAllView = (TextView) mView.findViewById(R.id.show_all); // Remove any previous clickable spans - we're recycling views between fragments for efficiency UIUtils.removeAllClickableSpans(mShowAllView); mShowAllClick = new ClickableSpan() { public void onClick(View v) { mController.setRoutesFilter(new ArrayList<String>()); } }; UIUtils.setClickableSpan(mShowAllView, mShowAllClick); mNoArrivals = (TextView) mView.findViewById(R.id.no_arrivals); // First ETA row mEtaContainer1 = mView.findViewById(R.id.eta_container1); mEtaRouteFavorite1 = (ImageButton) mEtaContainer1.findViewById(R.id.eta_route_favorite); mEtaRouteFavorite1.setColorFilter(mView.getResources().getColor(R.color.header_text_color)); mEtaReminder1 = (ImageButton) mEtaContainer1.findViewById(R.id.reminder); mEtaReminder1.setColorFilter(mView.getResources().getColor(R.color.header_text_color)); mEtaRouteName1 = (TextView) mEtaContainer1.findViewById(R.id.eta_route_name); mEtaRouteDirection1 = (TextView) mEtaContainer1.findViewById(R.id.eta_route_direction); mEtaAndMin1 = (RelativeLayout) mEtaContainer1.findViewById(R.id.eta_and_min); mEtaArrivalInfo1 = (TextView) mEtaContainer1.findViewById(R.id.eta); mEtaMin1 = (TextView) mEtaContainer1.findViewById(R.id.eta_min); mEtaRealtime1 = (ViewGroup) mEtaContainer1.findViewById(R.id.eta_realtime_indicator); mEtaMoreVert1 = (ImageButton) mEtaContainer1.findViewById(R.id.eta_more_vert); mEtaMoreVert1.setColorFilter(mView.getResources().getColor(R.color.header_text_color)); mEtaSeparator = mView.findViewById(R.id.eta_separator); // Second ETA row mEtaContainer2 = mView.findViewById(R.id.eta_container2); mEtaRouteFavorite2 = (ImageButton) mEtaContainer2.findViewById(R.id.eta_route_favorite); mEtaRouteFavorite2.setColorFilter(mView.getResources().getColor(R.color.header_text_color)); mEtaReminder2 = (ImageButton) mEtaContainer2.findViewById(R.id.reminder); mEtaReminder2.setColorFilter(mView.getResources().getColor(R.color.header_text_color)); mEtaRouteName2 = (TextView) mEtaContainer2.findViewById(R.id.eta_route_name); mEtaAndMin2 = (RelativeLayout) mEtaContainer2.findViewById(R.id.eta_and_min); mEtaRouteDirection2 = (TextView) mEtaContainer2.findViewById(R.id.eta_route_direction); mEtaArrivalInfo2 = (TextView) mEtaContainer2.findViewById(R.id.eta); mEtaMin2 = (TextView) mEtaContainer2.findViewById(R.id.eta_min); mEtaRealtime2 = (ViewGroup) mEtaContainer2.findViewById(R.id.eta_realtime_indicator); mEtaMoreVert2 = (ImageButton) mEtaContainer2.findViewById(R.id.eta_more_vert); mEtaMoreVert2.setColorFilter(mView.getResources().getColor(R.color.header_text_color)); mProgressBar = (ProgressBar) mView.findViewById(R.id.header_loading_spinner); mStopInfo = (ImageButton) mView.findViewById(R.id.stop_info_button); mExpandCollapse = (ImageView) mView.findViewById(R.id.expand_collapse); mAlertView = (ImageView) mView.findViewById(R.id.alert); mAlertView.setColorFilter(mView.getResources().getColor(R.color.header_text_color)); mAlertView.setVisibility(View.GONE); resetExpandCollapseAnimation(); // Initialize right margin view visibilities UIUtils.showViewWithAnimation(mProgressBar, mShortAnimationDuration); UIUtils.hideViewWithAnimation(mEtaContainer1, mShortAnimationDuration); UIUtils.hideViewWithAnimation(mEtaSeparator, mShortAnimationDuration); UIUtils.hideViewWithAnimation(mEtaContainer2, mShortAnimationDuration); // Initialize stop info view final ObaRegion obaRegion = Application.get().getCurrentRegion(); if (obaRegion == null || TextUtils.isEmpty(obaRegion.getStopInfoUrl())) { // This region doesn't support StopInfo - hide the info icon mStopInfo.setVisibility(View.GONE); } else { mStopInfo.setVisibility(View.VISIBLE); mStopInfo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Assemble StopInfo URL for the current stop Uri stopInfoUri = Uri.parse(obaRegion.getStopInfoUrl()); Uri.Builder stopInfoBuilder = stopInfoUri.buildUpon(); stopInfoBuilder.appendPath(mContext.getString(R.string.stop_info_url_path)); stopInfoBuilder.appendPath(mController.getStopId()); Log.d(TAG, "StopInfoUrl - " + stopInfoBuilder.build()); Intent i = new Intent(Intent.ACTION_VIEW); i.setData(stopInfoBuilder.build()); mContext.startActivity(i); //Analytics if (obaRegion != null && obaRegion.getName() != null) ObaAnalytics.reportEventWithCategory(ObaAnalytics.ObaEventCategory.UI_ACTION.toString(), mContext.getString(R.string.analytics_action_button_press), mContext.getString(R.string.analytics_label_button_press_stopinfo) + obaRegion.getName()); } }); } mStopFavorite.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mController.setFavoriteStop(!mController.isFavoriteStop()); refreshStopFavorite(); } }); mNameView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { beginNameEdit(null); } }); // Implement the "Save" and "Clear" buttons View save = mView.findViewById(R.id.edit_name_save); save.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mController.setUserStopName(mEditNameView.getText().toString()); endNameEdit(); } }); mEditNameView.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE) { mController.setUserStopName(mEditNameView.getText().toString()); endNameEdit(); return true; } return false; } }); // "Cancel" View cancel = mView.findViewById(R.id.edit_name_cancel); cancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { endNameEdit(); } }); View clear = mView.findViewById(R.id.edit_name_revert); clear.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mController.setUserStopName(null); endNameEdit(); } }); }
From source file:com.sentaroh.android.TaskAutomation.ActivityTaskStatus.java
@Override final public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder;/*from ww w.j av a 2 s . c o m*/ View v = convertView; if (v == null) { LayoutInflater vi = (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE); v = vi.inflate(id, null); holder = new ViewHolder(); holder.tv_active_state = (TextView) v.findViewById(R.id.task_status_list_item_active_state); holder.tv_grp = (TextView) v.findViewById(R.id.task_status_list_item_grp); holder.tv_task = (TextView) v.findViewById(R.id.task_status_list_item_task); holder.btn_cancel = (Button) v.findViewById(R.id.task_status_list_item_cancel_btn); holder.config = v.getResources().getConfiguration(); v.setTag(holder); } else { holder = (ViewHolder) v.getTag(); } final TaskStatusActiveTaskListItem o = getItem(position); if (o != null) { if (o.task_name.startsWith("No")) { holder.tv_task.setText("No active tasks"); holder.tv_active_state.setVisibility(TextView.GONE); holder.tv_grp.setVisibility(TextView.GONE); holder.btn_cancel.setVisibility(Button.GONE); } else { holder.tv_active_state.setText(o.task_active_state.substring(0, 1)); holder.tv_active_state.setVisibility(TextView.VISIBLE); holder.tv_grp.setText(o.profile_grp); holder.tv_task.setText(o.task_name); holder.tv_grp.setVisibility(TextView.VISIBLE); holder.btn_cancel.setVisibility(Button.VISIBLE); } final int p = position; holder.btn_cancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (ntfy_listener != null) ntfy_listener.notifyToListener(true, new Object[] { o.profile_grp, o.task_name }); remove(p); if (items.size() == 0) { TaskStatusActiveTaskListItem atl = new TaskStatusActiveTaskListItem(); atl.task_name = "No tasks"; items.add(atl); } notifyDataSetChanged(); } }); } return v; }
From source file:com.ivalentin.margolariak.SettingsLayout.java
/** * Run when the fragment is inflated./*from w w w . j av a 2 s .c om*/ * Assigns the view and the click listeners. * * @param inflater A LayoutInflater to manage views * @param container The container View * @param savedInstanceState Bundle containing the state * * @see android.support.v4.app.Fragment#onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle) */ @SuppressLint("InflateParams") //Throws unknown error when done properly. @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { //Load the layout final View view = inflater.inflate(R.layout.fragment_layout_settings, null); //Set the title ((MainActivity) getActivity()).setSectionTitle(view.getContext().getString(R.string.menu_settings)); //Get views. RelativeLayout rlNotification = (RelativeLayout) view.findViewById(R.id.rl_settings_notifications); final CheckBox cbNotification = (CheckBox) view.findViewById(R.id.cb_settings_notifications); final TextView tvNotification = (TextView) view.findViewById(R.id.tv_settings_notifications_summary); TextView tvLicense = (TextView) view.findViewById(R.id.tv_setting_license); TextView tvPrivacy = (TextView) view.findViewById(R.id.tv_setting_privacy); TextView tvAbout = (TextView) view.findViewById(R.id.tv_setting_about); TextView tvTransparency = (TextView) view.findViewById(R.id.tv_setting_transparency); //Set initial state of the notification settings SharedPreferences settings = view.getContext().getSharedPreferences(GM.PREFERENCES.PREFERNCES, Context.MODE_PRIVATE); if (settings.getBoolean(GM.PREFERENCES.KEY.NOTIFICATIONS, GM.PREFERENCES.DEFAULT.NOTIFICATIONS)) { cbNotification.setChecked(true); tvNotification.setText(view.getContext().getString(R.string.settings_notification_on)); } else { cbNotification.setChecked(false); tvNotification.setText(view.getContext().getString(R.string.settings_notification_off)); } //Set click listener for "Notification" preference rlNotification.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (cbNotification.isChecked()) { cbNotification.setChecked(false); tvNotification.setText(view.getContext().getString(R.string.settings_notification_off)); SharedPreferences preferences = view.getContext() .getSharedPreferences(GM.PREFERENCES.PREFERNCES, Context.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); editor.putBoolean(GM.PREFERENCES.KEY.NOTIFICATIONS, false); editor.apply(); } else { cbNotification.setChecked(true); tvNotification.setText(view.getContext().getString(R.string.settings_notification_on)); SharedPreferences preferences = view.getContext() .getSharedPreferences(GM.PREFERENCES.PREFERNCES, Context.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); editor.putBoolean(GM.PREFERENCES.KEY.NOTIFICATIONS, true); editor.apply(); } } }); //Set listener for the other buttons tvLicense.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String title = v.getResources().getString(R.string.settings_license); String text = v.getResources().getString(R.string.settings_license_content); showDialog(title, text); } }); tvPrivacy.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String title = v.getResources().getString(R.string.settings_privacy); String text = v.getResources().getString(R.string.settings_privacy_content); showDialog(title, text); } }); tvAbout.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String title = v.getResources().getString(R.string.settings_about); String text = v.getResources().getString(R.string.settings_about_content); showDialog(title, text); } }); tvTransparency.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String title = v.getResources().getString(R.string.settings_transparency); String text = v.getResources().getString(R.string.settings_transparency_content); showDialog(title, text); } }); return view; }
From source file:com.df.app.procedures.CarRecogniseLayout.java
/** * /*www.j a v a2s .c o m*/ * @param arrayId * @param editViewId */ private void choose(final int arrayId, final int editViewId) { View view1 = ((Activity) getContext()).getLayoutInflater().inflate(R.layout.popup_layout, null); final AlertDialog dialog = new AlertDialog.Builder(getContext()).setView(view1).create(); TableLayout contentArea = (TableLayout) view1.findViewById(R.id.contentArea); final ListView listView = new ListView(view1.getContext()); listView.setAdapter(new ArrayAdapter<String>(view1.getContext(), android.R.layout.simple_list_item_1, view1.getResources().getStringArray(arrayId))); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { dialog.dismiss(); String temp = (String) listView.getItemAtPosition(i); setEditViewText(rootView, editViewId, temp); } }); contentArea.addView(listView); setTextView(view1, R.id.title, getResources().getString(R.string.alert)); dialog.show(); }
From source file:com.sentaroh.android.TaskAutomation.ActivityTaskStatus.java
@Override final public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder;/*from ww w .java 2s . co m*/ View v = convertView; if (v == null) { LayoutInflater vi = (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE); v = vi.inflate(id, null); holder = new ViewHolder(); holder.tv_time = (TextView) v.findViewById(R.id.task_history_list_item_time); holder.tv_status = (TextView) v.findViewById(R.id.task_history_list_item_status); holder.tv_grp = (TextView) v.findViewById(R.id.task_history_list_item_grp); holder.tv_task = (TextView) v.findViewById(R.id.task_history_list_item_task); holder.tv_msg = (TextView) v.findViewById(R.id.task_history_list_item_msg); holder.stat_success = c.getString(R.string.msgs_status_view_stat_success); holder.stat_error = c.getString(R.string.msgs_status_view_stat_error); holder.stat_cancelled = c.getString(R.string.msgs_status_view_stat_cancelled); holder.stat_started = c.getString(R.string.msgs_status_view_stat_started); holder.config = v.getResources().getConfiguration(); if (ll_background == null) ll_background = holder.tv_time.getBackground(); v.setTag(holder); } else { holder = (ViewHolder) v.getTag(); } TaskStatusTaskHistoryListItem o = getItem(position); if (o != null) { holder.tv_time.setTextColor(Color.WHITE); holder.tv_status.setTextColor(Color.WHITE); holder.tv_grp.setTextColor(Color.WHITE); holder.tv_task.setTextColor(Color.WHITE); holder.tv_msg.setTextColor(Color.WHITE); if (o.task_name.startsWith("No")) { holder.tv_time.setText("No task history"); holder.tv_status.setText(""); holder.tv_grp.setText(""); holder.tv_task.setText(""); holder.tv_msg.setVisibility(TextView.GONE); } else { holder.tv_time.setText(o.end_time); if (o.task_status.equals(TaskHistoryItem.TASK_HISTORY_TASK_STATUS_STARTED)) holder.tv_status.setText("A"); else if (o.task_status.equals(TaskHistoryItem.TASK_HISTORY_TASK_STATUS_QUEUED)) holder.tv_status.setText("Q"); else if (o.task_status.equals(TaskHistoryItem.TASK_HISTORY_TASK_STATUS_ENDED)) holder.tv_status.setText("S"); if (o.result.equals(TaskResponse.RESP_CHAR_SUCCESS)) { } else if (o.result.equals(TaskResponse.RESP_CHAR_ERROR)) { holder.tv_status.setText("E"); holder.tv_time.setTextColor(Color.RED); holder.tv_status.setTextColor(Color.RED); holder.tv_grp.setTextColor(Color.RED); holder.tv_task.setTextColor(Color.RED); holder.tv_msg.setTextColor(Color.RED); } else if (o.result.equals(TaskResponse.RESP_CHAR_CANCELLED)) { holder.tv_status.setText("C"); holder.tv_time.setTextColor(Color.YELLOW); holder.tv_status.setTextColor(Color.YELLOW); holder.tv_grp.setTextColor(Color.YELLOW); holder.tv_task.setTextColor(Color.YELLOW); holder.tv_msg.setTextColor(Color.YELLOW); } else if (o.result.equals(NTFY_TO_SVC_TASK_STARTED)) { holder.tv_status.setText("A"); } holder.tv_msg.setVisibility(TextView.GONE); holder.tv_grp.setText(o.profile_grp); holder.tv_task.setText(o.task_name); if (!o.msg_text.equals("") && !o.msg_text.equals(" ")) { holder.tv_msg.setText(o.msg_text); holder.tv_msg.setVisibility(TextView.VISIBLE); } } } return v; }
From source file:com.yacorso.nowaste.views.adapters.FridgeFoodAdapter.java
@Override public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, final int position) { final FridgeViewHolder holder = (FridgeViewHolder) viewHolder; final Food food = foodList.get(position); final int quantity = food.getFoodFridge().getQuantity(); holder.tvName.setText(food.getName()); holder.btnQuantity.setText(Integer.toString(quantity)); Date outOfDate = food.getFoodFridge().getOutOfDate(); holder.outOfDate.setText(getDateTextFromDate(outOfDate)); setOpenIcon(holder.btnOpenToggle, food); setColorCircleFromDate(holder.btnQuantity, outOfDate, mContext.getResources()); View.OnClickListener clickListener = new View.OnClickListener() { @Override//from w ww. j av a 2s. c o m public void onClick(View v) { lastFoodClickedPosition = position; switch (v.getId()) { case R.id.btn_food_quantity: /* * Popup changement quantit */ final NumberPicker numberPicker = new NumberPicker(mContext); numberPicker.setMinValue(1); numberPicker.setMaxValue(100); numberPicker.setValue(quantity); numberPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS); AlertDialog.Builder builder = new AlertDialog.Builder(mContext); builder.setMessage(R.string.title_quantity_number_picker); builder.setView(numberPicker); builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { /* * Save the modification */ int selectedValue = numberPicker.getValue(); food.getFoodFridge().setQuantity(selectedValue); mFoodProvider.update(food); } }); builder.setNegativeButton(android.R.string.cancel, null); builder.create().show(); break; case R.id.btn_open_toggle: /* * Open/close food */ FoodFridge foodFridge = food.getFoodFridge(); foodFridge.toggleOpen(); setOpenIcon(v, food); Date outOfDate = foodFridge.getOutOfDate(); setColorCircleFromDate(holder.btnQuantity, outOfDate, v.getResources()); mFoodProvider.update(food); break; case R.id.item_text_zone: EventBus.getDefault().post(new CallUpdateFoodEvent(food)); break; case R.id.btn_favorite_toggle: EventBus.getDefault().post(new CallAddFoodToCustomListEvent(food)); break; } } }; holder.btnQuantity.setOnClickListener(clickListener); holder.btnOpenToggle.setOnClickListener(clickListener); holder.btnFavoriteToggle.setOnClickListener(clickListener); holder.textZone.setOnClickListener(clickListener); }
From source file:com.nickandjerry.dynamiclayoutinflator.DynamicLayoutInflator.java
@SuppressLint("NewApi") private static void applyAttributes(View view, Map<String, String> attrs, ViewGroup parent) { if (viewRunnables == null) createViewRunnables();/*from ww w.jav a2 s. c om*/ ViewGroup.LayoutParams layoutParams = view.getLayoutParams(); int layoutRule; int marginLeft = 0, marginRight = 0, marginTop = 0, marginBottom = 0, paddingLeft = 0, paddingRight = 0, paddingTop = 0, paddingBottom = 0; boolean hasCornerRadius = false, hasCornerRadii = false; for (Map.Entry<String, String> entry : attrs.entrySet()) { String attr = entry.getKey(); if (viewRunnables.containsKey(attr)) { viewRunnables.get(attr).apply(view, entry.getValue(), parent, attrs); continue; } if (attr.startsWith("cornerRadius")) { hasCornerRadius = true; hasCornerRadii = !attr.equals("cornerRadius"); continue; } layoutRule = NO_LAYOUT_RULE; boolean layoutTarget = false; switch (attr) { case "id": String idValue = parseId(entry.getValue()); if (parent != null) { DynamicLayoutInfo info = getDynamicLayoutInfo(parent); int newId = highestIdNumberUsed++; view.setId(newId); info.nameToIdNumber.put(idValue, newId); } break; case "width": case "layout_width": switch (entry.getValue()) { case "wrap_content": layoutParams.width = ViewGroup.LayoutParams.WRAP_CONTENT; break; case "fill_parent": case "match_parent": layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT; break; default: layoutParams.width = DimensionConverter.stringToDimensionPixelSize(entry.getValue(), view.getResources().getDisplayMetrics(), parent, true); break; } break; case "height": case "layout_height": switch (entry.getValue()) { case "wrap_content": layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT; break; case "fill_parent": case "match_parent": layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT; break; default: layoutParams.height = DimensionConverter.stringToDimensionPixelSize(entry.getValue(), view.getResources().getDisplayMetrics(), parent, false); break; } break; case "layout_gravity": if (parent != null && parent instanceof LinearLayout) { ((LinearLayout.LayoutParams) layoutParams).gravity = parseGravity(entry.getValue()); } else if (parent != null && parent instanceof FrameLayout) { ((FrameLayout.LayoutParams) layoutParams).gravity = parseGravity(entry.getValue()); } break; case "layout_weight": if (parent != null && parent instanceof LinearLayout) { ((LinearLayout.LayoutParams) layoutParams).weight = Float.parseFloat(entry.getValue()); } break; case "layout_below": layoutRule = RelativeLayout.BELOW; layoutTarget = true; break; case "layout_above": layoutRule = RelativeLayout.ABOVE; layoutTarget = true; break; case "layout_toLeftOf": layoutRule = RelativeLayout.LEFT_OF; layoutTarget = true; break; case "layout_toRightOf": layoutRule = RelativeLayout.RIGHT_OF; layoutTarget = true; break; case "layout_alignBottom": layoutRule = RelativeLayout.ALIGN_BOTTOM; layoutTarget = true; break; case "layout_alignTop": layoutRule = RelativeLayout.ALIGN_TOP; layoutTarget = true; break; case "layout_alignLeft": case "layout_alignStart": layoutRule = RelativeLayout.ALIGN_LEFT; layoutTarget = true; break; case "layout_alignRight": case "layout_alignEnd": layoutRule = RelativeLayout.ALIGN_RIGHT; layoutTarget = true; break; case "layout_alignParentBottom": layoutRule = RelativeLayout.ALIGN_PARENT_BOTTOM; break; case "layout_alignParentTop": layoutRule = RelativeLayout.ALIGN_PARENT_TOP; break; case "layout_alignParentLeft": case "layout_alignParentStart": layoutRule = RelativeLayout.ALIGN_PARENT_LEFT; break; case "layout_alignParentRight": case "layout_alignParentEnd": layoutRule = RelativeLayout.ALIGN_PARENT_RIGHT; break; case "layout_centerHorizontal": layoutRule = RelativeLayout.CENTER_HORIZONTAL; break; case "layout_centerVertical": layoutRule = RelativeLayout.CENTER_VERTICAL; break; case "layout_centerInParent": layoutRule = RelativeLayout.CENTER_IN_PARENT; break; case "layout_margin": marginLeft = marginRight = marginTop = marginBottom = DimensionConverter .stringToDimensionPixelSize(entry.getValue(), view.getResources().getDisplayMetrics()); break; case "layout_marginLeft": marginLeft = DimensionConverter.stringToDimensionPixelSize(entry.getValue(), view.getResources().getDisplayMetrics(), parent, true); break; case "layout_marginTop": marginTop = DimensionConverter.stringToDimensionPixelSize(entry.getValue(), view.getResources().getDisplayMetrics(), parent, false); break; case "layout_marginRight": marginRight = DimensionConverter.stringToDimensionPixelSize(entry.getValue(), view.getResources().getDisplayMetrics(), parent, true); break; case "layout_marginBottom": marginBottom = DimensionConverter.stringToDimensionPixelSize(entry.getValue(), view.getResources().getDisplayMetrics(), parent, false); break; case "padding": paddingBottom = paddingLeft = paddingRight = paddingTop = DimensionConverter .stringToDimensionPixelSize(entry.getValue(), view.getResources().getDisplayMetrics()); break; case "paddingLeft": paddingLeft = DimensionConverter.stringToDimensionPixelSize(entry.getValue(), view.getResources().getDisplayMetrics()); break; case "paddingTop": paddingTop = DimensionConverter.stringToDimensionPixelSize(entry.getValue(), view.getResources().getDisplayMetrics()); break; case "paddingRight": paddingRight = DimensionConverter.stringToDimensionPixelSize(entry.getValue(), view.getResources().getDisplayMetrics()); break; case "paddingBottom": paddingBottom = DimensionConverter.stringToDimensionPixelSize(entry.getValue(), view.getResources().getDisplayMetrics()); break; } if (layoutRule != NO_LAYOUT_RULE && parent instanceof RelativeLayout) { if (layoutTarget) { int anchor = idNumFromIdString(parent, parseId(entry.getValue())); ((RelativeLayout.LayoutParams) layoutParams).addRule(layoutRule, anchor); } else if (entry.getValue().equals("true")) { ((RelativeLayout.LayoutParams) layoutParams).addRule(layoutRule); } } } // TODO: this is a giant mess; come up with a simpler way of deciding what to draw for the background if (attrs.containsKey("background") || attrs.containsKey("borderColor")) { String bgValue = attrs.containsKey("background") ? attrs.get("background") : null; if (bgValue != null && bgValue.startsWith("@drawable/")) { view.setBackground(getDrawableByName(view, bgValue)); } else if (bgValue == null || bgValue.startsWith("#") || bgValue.startsWith("@color")) { if (view instanceof Button || attrs.containsKey("pressedColor")) { int bgColor = parseColor(view, bgValue == null ? "#00000000" : bgValue); int pressedColor; if (attrs.containsKey("pressedColor")) { pressedColor = parseColor(view, attrs.get("pressedColor")); } else { pressedColor = adjustBrightness(bgColor, 0.9f); } GradientDrawable gd = new GradientDrawable(); gd.setColor(bgColor); GradientDrawable pressedGd = new GradientDrawable(); pressedGd.setColor(pressedColor); if (hasCornerRadii) { float radii[] = new float[8]; for (int i = 0; i < CORNERS.length; i++) { String corner = CORNERS[i]; if (attrs.containsKey("cornerRadius" + corner)) { radii[i * 2] = radii[i * 2 + 1] = DimensionConverter.stringToDimension( attrs.get("cornerRadius" + corner), view.getResources().getDisplayMetrics()); } gd.setCornerRadii(radii); pressedGd.setCornerRadii(radii); } } else if (hasCornerRadius) { float cornerRadius = DimensionConverter.stringToDimension(attrs.get("cornerRadius"), view.getResources().getDisplayMetrics()); gd.setCornerRadius(cornerRadius); pressedGd.setCornerRadius(cornerRadius); } if (attrs.containsKey("borderColor")) { String borderWidth = "1dp"; if (attrs.containsKey("borderWidth")) { borderWidth = attrs.get("borderWidth"); } int borderWidthPx = DimensionConverter.stringToDimensionPixelSize(borderWidth, view.getResources().getDisplayMetrics()); gd.setStroke(borderWidthPx, parseColor(view, attrs.get("borderColor"))); pressedGd.setStroke(borderWidthPx, parseColor(view, attrs.get("borderColor"))); } StateListDrawable selector = new StateListDrawable(); selector.addState(new int[] { android.R.attr.state_pressed }, pressedGd); selector.addState(new int[] {}, gd); view.setBackground(selector); getDynamicLayoutInfo(view).bgDrawable = gd; } else if (hasCornerRadius || attrs.containsKey("borderColor")) { GradientDrawable gd = new GradientDrawable(); int bgColor = parseColor(view, bgValue == null ? "#00000000" : bgValue); gd.setColor(bgColor); if (hasCornerRadii) { float radii[] = new float[8]; for (int i = 0; i < CORNERS.length; i++) { String corner = CORNERS[i]; if (attrs.containsKey("cornerRadius" + corner)) { radii[i * 2] = radii[i * 2 + 1] = DimensionConverter.stringToDimension( attrs.get("cornerRadius" + corner), view.getResources().getDisplayMetrics()); } gd.setCornerRadii(radii); } } else if (hasCornerRadius) { float cornerRadius = DimensionConverter.stringToDimension(attrs.get("cornerRadius"), view.getResources().getDisplayMetrics()); gd.setCornerRadius(cornerRadius); } if (attrs.containsKey("borderColor")) { String borderWidth = "1dp"; if (attrs.containsKey("borderWidth")) { borderWidth = attrs.get("borderWidth"); } gd.setStroke( DimensionConverter.stringToDimensionPixelSize(borderWidth, view.getResources().getDisplayMetrics()), parseColor(view, attrs.get("borderColor"))); } view.setBackground(gd); getDynamicLayoutInfo(view).bgDrawable = gd; } else { view.setBackgroundColor(parseColor(view, bgValue)); } } } if (layoutParams instanceof ViewGroup.MarginLayoutParams) { ((ViewGroup.MarginLayoutParams) layoutParams).setMargins(marginLeft, marginTop, marginRight, marginBottom); } view.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom); view.setLayoutParams(layoutParams); }
From source file:com.grarak.kerneladiutor.views.recyclerview.downloads.DownloadKernelView.java
private void checkMD5(final String md5, final String path, final String installMethod) { if (mCheckMD5Task == null) { mCheckMD5Task = new ThreadTask<Void, Boolean>(mActvity) { private int mSelection; @Override/*from ww w. j av a 2 s .co m*/ public void onPreExecute() { super.onPreExecute(); mDownloadSection.setVisibility(View.GONE); } @Override public Boolean doInBackground(Void arg) { return Utils.checkMD5(md5, new File(path)); } @Override public void onPostExecute(Boolean ret) { super.onPostExecute(ret); if (ret) { mInstallButton.setVisibility(View.VISIBLE); mInstallButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View view) { if (!Utils.existFile(path)) { Utils.toast(view.getContext().getString(R.string.went_wrong), view.getContext()); return; } if (installMethod != null) { ViewUtils.dialogBuilder(view.getContext().getString(R.string.sure_question), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { } }, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { RootUtils.runCommand(installMethod.replace("$FILE", path)); RootUtils.runCommand("rm -f " + path); RootUtils.runCommand("reboot"); } }, new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialogInterface) { } }, view.getContext()) .setTitle(view.getContext().getString(R.string.install)).show(); } else { String[] items = view.getResources().getStringArray(R.array.downloads_recovery); new Dialog(view.getContext()) .setSingleChoiceItems(items, 0, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { mSelection = i; } }).setPositiveButton(view.getContext().getString(R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { if (mSelection == 2) { Utils.toast( view.getContext().getString( R.string.file_location, path), view.getContext()); return; } Recovery recovery = new Recovery( Recovery.RECOVERY_COMMAND.FLASH_ZIP, new File(path)); Recovery.RECOVERY type = mSelection == 1 ? Recovery.RECOVERY.TWRP : Recovery.RECOVERY.CWM; RootFile recoveryFile = new RootFile( "/cache/recovery/" + recovery.getFile(type)); for (String command : recovery.getCommands(type)) { recoveryFile.write(command, true); } RootUtils.runCommand("reboot recovery"); } }) .show(); } } }); } else { mMismatchMD5.setVisibility(View.VISIBLE); } mCheckMD5.setVisibility(View.GONE); mDownloadSection.setVisibility(View.VISIBLE); mCheckMD5Task = null; } }.execute(null); } }