@SuppressWarnings("deprecation") @Override public View getView(int position, View convertView, ViewGroup parent) { TextView view; if (convertView == null) { view = (TextView) LayoutInflater.from(mContext).inflate(R.layout.choose_item, parent, false); } else { view = (TextView) convertView; } view.setTag(position); String mString = ""; if (mListData != null) { if (position < mListData.size()) { mString = mListData.get(position).getName(); } } if (mString.contains("不限")) view.setText("不限"); else view.setText(mString); view.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize); if (selectedText != null && selectedText.equals(mString)) { view.setBackgroundDrawable(selectedDrawble); // 设置选中的背景图 } else { view.setBackgroundDrawable(mContext.getResources().getDrawable(normalDrawbleId)); } view.setPadding(20, 0, 0, 0); view.setOnClickListener(onClickListener); return view; }
/** * add new tab with title text * * @param title title text */ public void addTab(CharSequence title) { int layoutId = getLayoutId(type); TextView tv = (TextView) inflater.inflate(layoutId, tabWidget, false); tv.setText(title); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { // tv.setBackgroundResource(R.drawable.mth_tab_widget_background_ripple); } else { // create background using colorControlActivated StateListDrawable d = new StateListDrawable(); d.addState( new int[] {android.R.attr.state_pressed}, new ColorDrawable(colorControlActivated)); d.setAlpha(180); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { tv.setBackgroundDrawable(d); } else { tv.setBackgroundDrawable(d); } } int tabId = tabWidget.getTabCount(); addTab(newTabSpec(String.valueOf(tabId)).setIndicator(tv).setContent(android.R.id.tabcontent)); }
public void showTabContents(int id) { Log.d(TAG, "showTabContents id=" + id); mInputContainer.setVisibility(View.GONE); mInputLabel.setBackgroundDrawable(mNormalTabImage); mOutputContainer.setVisibility(View.GONE); mOutputLabel.setBackgroundDrawable(mNormalTabImage); mWikiContainer.setVisibility(View.GONE); mWikiLabel.setBackgroundDrawable(mNormalTabImage); mDebugContainer.setVisibility(View.GONE); mDebugLabel.setBackgroundDrawable(mNormalTabImage); if (id == R.id.main_input_label) { Log.d(TAG, "showTabContents -main_input_label id=" + id); mInputContainer.setVisibility(View.VISIBLE); mInputLabel.setBackgroundDrawable(mFocusedTabImage); } else if (id == R.id.main_output_label) { Log.d(TAG, "showTabContents -main_output_label id=" + id); mOutputContainer.setVisibility(View.VISIBLE); mOutputLabel.setBackgroundDrawable(mFocusedTabImage); } else if (id == R.id.main_wiki_label) { Log.d(TAG, "showTabContents -main_wiki_label id=" + id); mWikiContainer.setVisibility(View.VISIBLE); mWikiLabel.setBackgroundDrawable(mFocusedTabImage); } else if (id == R.id.main_debug_label) { Log.d(TAG, "showTabContents -main_debug_label id=" + id); mDebugContainer.setVisibility(View.VISIBLE); mDebugLabel.setBackgroundDrawable(mFocusedTabImage); } }
private void init() { LayoutInflater layoutInflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); layoutInflater.inflate(R.layout.book_folder_layout, this); folderName = (TextView) findViewById(R.id.view_cell_bookname_textView); downloadingView = findViewById(R.id.downloading_view); ThemeBean themeBean = ThemeManagerSingleton.getInstance.getNewThemeModel().getThemeBean(); Drawable numberTextBackDrawable = ThemeBuilder.getBitmapAccordingScreenDensity( getContext(), themeBean.getBookCountBackgroundInFolderCell()); textView = (TextView) findViewById(R.id.book_number_textView); textView.setBackgroundDrawable(numberTextBackDrawable); // TODO try { byte imgdata[] = ThemeBuilder.InputStreamToByte( ThemeBuilder.getInputStreamAccordingScreenDensity(getContext(), "downloading")); ((GifMovieView) downloadingView).setMovieByteArray(imgdata); } catch (IOException e) { e.printStackTrace(); } gridLayout = (MyGridLayout) findViewById(R.id.book_folder_gridLayout); gridLayout.setColumnCount(2); gridLayout.setRowCount(2); }
public List<TextView> buildSpannable(List<Tag> tags) { List<TextView> views = new ArrayList<TextView>(); for (Tag g : tags) { TextView view = new TextView(getContext()); view.setText("#" + g.content); view.setTag(g); MarginLayoutParams params = new MarginLayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); final int margin = U.dp2px(4); params.setMargins(margin * 2, margin, margin * 2, margin); view.setLayoutParams(params); view.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { FeedsSearchActivity.start(getContext(), ((Tag) v.getTag()).content); } }); final int padding = U.dp2px(8); view.setPadding(padding * 2, padding, padding * 2, padding); view.setBackgroundDrawable( new RoundRectDrawable( U.dp2px(4), getContext().getResources().getColorStateList(R.color.apptheme_primary_white_btn))); views.add(view); } return views; }
/** * 节点浏览示例 * * @param v */ public void nodeClick(View v) { if (nodeIndex < -1 || route == null || nodeIndex >= route.getNumSteps()) return; viewCache = getLayoutInflater().inflate(R.layout.custom_text_view, null); popupText = (TextView) viewCache.findViewById(R.id.textcache); // 上一个节点 if (mBtnPre.equals(v) && nodeIndex > 0) { // 索引减 nodeIndex--; // 移动到指定索引的坐标 mMapView.getController().animateTo(route.getStep(nodeIndex).getPoint()); // 弹出泡泡 popupText.setText(route.getStep(nodeIndex).getContent()); popupText.setBackgroundResource(R.drawable.popup); pop.showPopup(BMapUtil.getBitmapFromView(popupText), route.getStep(nodeIndex).getPoint(), 5); } // 下一个节点 if (mBtnNext.equals(v) && nodeIndex < (route.getNumSteps() - 1)) { // 索引加 nodeIndex++; // 移动到指定索引的坐标 mMapView.getController().animateTo(route.getStep(nodeIndex).getPoint()); // 弹出泡泡 popupText.setText(route.getStep(nodeIndex).getContent()); popupText.setBackgroundDrawable(getResources().getDrawable(R.drawable.popup)); pop.showPopup(BMapUtil.getBitmapFromView(popupText), route.getStep(nodeIndex).getPoint(), 5); } }
private void updateBatteryView(int charge) { if (batteryView != null) { batteryView.setVisibility(View.VISIBLE); batteryView.setBackgroundDrawable( getResources().getDrawable(R.drawable.battery_icon_general)); batteryView.setTextColor(getResources().getColor(android.R.color.white)); // if (charge >= 70) { // // batteryView.setBackgroundDrawable(getResources().getDrawable(R.drawable.battery_icon_high)); // // batteryView.setTextColor(getResources().getColor(R.color.battery_text_color)); // } else if (charge >= 35 && charge < 70) { // // batteryView.setBackgroundDrawable(getResources().getDrawable(R.drawable.battery_icon_average)); // // batteryView.setTextColor(getResources().getColor(R.color.actis_app_yellow_accent)); // } else { // // batteryView.setBackgroundDrawable(getResources().getDrawable(R.drawable.battery_icon_low)); // // batteryView.setTextColor(getResources().getColor(R.color.actis_app_red_accent)); // } batteryView.setText(charge + "%"); } }
public void handleMessage(Message msg) { switch (msg.what) { case OK: Drawable a = t1.getBackground(); t1.setBackgroundDrawable(t2.getBackground()); t2.setBackgroundDrawable(t3.getBackground()); t3.setBackgroundDrawable(t4.getBackground()); t4.setBackgroundDrawable(a); // t1.setBackgroundColor(color[c%color.length]); // t2.setBackgroundColor(color[(c+1)%color.length]); // t3.setBackgroundColor(color[(c+2)%color.length]); // t4.setBackgroundColor(color[(c+3)%color.length]); break; default: break; } }
public final void updateView(final Invite invite, Context context) { nomer.setText(invite.getNomer()); date.setText(invite.getDate()); switch (invite.getType()) { case "Зелена карта": background.setBackgroundColor( context.getResources().getColor(android.R.color.holo_green_dark)); type.setBackgroundColor(context.getResources().getColor(android.R.color.holo_green_dark)); type.setText("Карта"); break; case "Сертифікат": background.setBackgroundColor(context.getResources().getColor(android.R.color.white)); type.setBackgroundColor(context.getResources().getColor(android.R.color.white)); type.setText("Cертиф."); break; case "Європротокол": background.setBackgroundColor(context.getResources().getColor(android.R.color.white)); type.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.eu)); type.setText(""); break; case "Тахограф": background.setBackgroundColor(context.getResources().getColor(android.R.color.white)); type.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.ta)); type.setText(""); break; case "Жовте свідоцтво": background.setBackgroundColor(Color.parseColor("#fff100")); type.setBackgroundColor(Color.parseColor("#fff100")); type.setText("Свід."); break; case "Страховка": background.setBackgroundColor(context.getResources().getColor(android.R.color.white)); type.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.stra)); type.setText(""); break; case "Масло": background.setBackgroundColor(context.getResources().getColor(android.R.color.white)); type.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.oil)); type.setText(""); break; } }
@Override public View getView(int position, View view, ViewGroup arg2) { LinearLayout ln = new LinearLayout(context); ln.setGravity(Gravity.CENTER); TextView item_tv = new TextView(context); item_tv.setText(list.get(position) + ""); int w = (screenWidth - 70) * 3 / 5 / 7; item_tv.setWidth(w); item_tv.setHeight(w); item_tv.setTextSize(15); item_tv.setGravity(Gravity.CENTER); item_tv.setId(949494); item_tv.setBackgroundColor(Color.parseColor("#eeeeee")); int num = Integer.parseInt(item_tv.getText().toString()); // 当天背景颜色为浅蓝色 if (isNowDate()) { if (position == todayPosition) { item_tv.setBackgroundDrawable( context.getResources().getDrawable(R.drawable.date_share_check_df)); item_tv.setTextColor(Color.WHITE); } } // 选中是背景 if (position < 7 && num > 7) { item_tv.setTextColor(Color.parseColor("#BEBBBB")); } else if (position > 14 && num < 7) { item_tv.setTextColor(Color.parseColor("#BEBBBB")); } else { item_tv.setTextColor(Color.parseColor("#858585")); // 点击时背景颜色高亮 if (list.get(position) == clickPosition) { item_tv.setBackgroundDrawable( context.getResources().getDrawable(R.drawable.date_share_check)); item_tv.setTextColor(Color.WHITE); } } ln.addView(item_tv); view = ln; return view; }
public void setSelected(boolean flag) { if (flag) { return; } else { mTextView.setTextColor(getContext().getResources().getColor(0x7f0c000f)); mTextView.setBackgroundDrawable(null); return; } }
private void stopDrag() { // doTask = false; ha.removeMessages(0); doTask = false; if (dragView != null) { mWindowManager.removeView(dragView); dragView.setBackgroundDrawable(null); dragView = null; } if (dragBitmap != null) { if (!dragBitmap.isRecycled()) dragBitmap.recycle(); dragBitmap = null; } }
@Override protected View createLoadedView() { ScrollView mScrollView = new ScrollView(UIUtils.getContext()); mScrollView.setFillViewport(true); // 设置可以填充父窗体 // 初始化布局,该布局可以自动分配子View位置,保持每一行都能对齐 FlowLayout mLayout = new FlowLayout(UIUtils.getContext()); mLayout.setBackgroundResource(R.drawable.grid_item_bg_normal); int layoutPadding = UIUtils.dip2px(13); mLayout.setPadding(layoutPadding, layoutPadding, layoutPadding, layoutPadding); mLayout.setHorizontalSpacing(layoutPadding); mLayout.setVerticalSpacing(layoutPadding); int textPaddingV = UIUtils.dip2px(4); int textPaddingH = UIUtils.dip2px(7); int backColor = 0xffcecece; int radius = UIUtils.dip2px(5); // 代码动态创建一个图片 GradientDrawable pressDrawable = DrawableUtils.createDrawable(backColor, backColor, radius); Random mRdm = new Random(); for (int i = 0; i < mDatas.size(); i++) { TextView tv = new TextView(UIUtils.getContext()); // 随机颜色的范围0x202020~0xefefef int red = 32 + mRdm.nextInt(208); int green = 32 + mRdm.nextInt(208); int blue = 32 + mRdm.nextInt(208); int color = 0xff000000 | (red << 16) | (green << 8) | blue; // 创建背景图片选择器 GradientDrawable normalDrawable = DrawableUtils.createDrawable(color, backColor, radius); StateListDrawable selector = DrawableUtils.createSelector(normalDrawable, pressDrawable); tv.setBackgroundDrawable(selector); final String text = mDatas.get(i); tv.setText(text); tv.setTextColor(Color.rgb(255, 255, 255)); tv.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); tv.setGravity(Gravity.CENTER); tv.setPadding(textPaddingH, textPaddingV, textPaddingH, textPaddingV); tv.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { UIUtils.showToastSafe(text); } }); mLayout.addView(tv); } mScrollView.addView(mLayout); return mScrollView; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); System.out.println("大家好"); ScrollView scrollView = new ScrollView(this); mFlowLayout = new FlowLayout(this); mFlowLayout.setPadding(8, 8, 8, 8); final Random random = new Random(); for (int i = 0; i < 100; i++) { final TextView textView = new TextView(this); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16); int nextInt = random.nextInt(1000) + 10; textView.setText(nextInt + ""); Drawable normal = DrawableUtil.getGradientDrawable(ColorUtil.getRandomColor()); Drawable pressed = DrawableUtil.getGradientDrawable(Color.GRAY); Drawable selector = DrawableUtil.getDrawableSelector(normal, pressed); textView.setBackgroundDrawable(selector); textView.setGravity(Gravity.CENTER_HORIZONTAL); textView.setPadding(5, 2, 5, 2); textView.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { Toast.makeText(MainActivity.this, textView.getText().toString(), 0).show(); ; } }); mFlowLayout.addView(textView); } scrollView.addView(mFlowLayout); setContentView(scrollView); }
// This rounds corners of image as well as textview and darkens latters background public void updateImage(Bitmap image) { LayoutParams params = new LayoutParams(width, LayoutParams.WRAP_CONTENT); setLayoutParams(params); // Image Bitmap bm; bm = BitmapUtils.getRoundedCornerBitmap(ctx, image, 0); mContentView.setImageBitmap(bm); // TextView background mTextView = (TextView) findViewById(R.id.mit150CorridorTV); bm = BitmapUtils.createRoundedBottomBitmap(ctx, width, 50, color); BitmapDrawable bd = new BitmapDrawable(bm); mTextView.setBackgroundDrawable(bd); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.qr_code_show_activity); mTitle = (TextView) findViewById(R.id.title_txt); mTitle.setText("扫描二维码"); back = (TextView) findViewById(R.id.title_back); back.setBackgroundDrawable(getResources().getDrawable(R.drawable.iconfont_fanhui)); mTextView = (TextView) findViewById(R.id.result); mImageView = (ImageView) findViewById(R.id.qrcode_bitmap); Intent intent = new Intent(); intent.setClass(QrCodeShowActivity.this, QrCodeCaptureActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivityForResult(intent, SCANNIN_GREQUEST_CODE); // 点击按钮跳转到二维码扫描界面,这里用的是startActivityForResult跳转 // 扫描完了之后调到该界面 new Timer() .schedule( new TimerTask() { public void run() { Intent intent = new Intent(); intent.setClass(QrCodeShowActivity.this, QrCodeCaptureActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivityForResult(intent, SCANNIN_GREQUEST_CODE); } }, 5000); Button mButton = (Button) findViewById(R.id.button1); mButton.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(); intent.setClass(QrCodeShowActivity.this, QrCodeCaptureActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivityForResult(intent, SCANNIN_GREQUEST_CODE); } }); }
public View getView(int position, View convertView, ViewGroup parent) { if (position == 0) { TextView view = (TextView) _inflater.inflate(R.layout.list_item, null); view.setText(R.string.add_rss_feed); return view; } if (position == 1) { TextView view = (TextView) _inflater.inflate(R.layout.list_item, null); view.setText(R.string.add_from_opml_file); return view; } if (position == 2) { TextView view = (TextView) _inflater.inflate(R.layout.list_item, null); view.setText(R.string.discover_subscriptions); return view; } if (position == 3) { View view = _inflater.inflate(R.layout.subscription_list_item, null); TextView text = (TextView) view.findViewById(R.id.text); text.setText("Link a GPodder account"); ImageView thumbnail = (ImageView) view.findViewById(R.id.thumbnail); thumbnail.setImageResource(R.drawable.mygpo); return view; } if (position == GOOGLE_ACCOUNT_START - 1) { TextView view = new TextView(ImportSubscriptionActivity.this); view.setTextAppearance( ImportSubscriptionActivity.this, android.R.style.TextAppearance_Medium); view.setBackgroundDrawable(getResources().getDrawable(R.drawable.back)); view.setText("Google Reader Accounts"); return view; } TextView view = (TextView) _inflater.inflate(R.layout.list_item, null); view.setText(_googleAccounts[position - GOOGLE_ACCOUNT_START].name); return view; }
/** * Add TextView IN LinearLayout * * @param parentll * @param tv * @param mContext */ private void addTextViewINLinearLayout(LinearLayout parentll, TextView tv, Context mContext) { int widthSoFar = 0; int maxWidth = 0; tv.measure(0, 0); tv.setTextSize(20); tv.setPadding(5, 5, 5, 5); tv.setTextColor(Color.BLACK); tv.setBackgroundDrawable(getResources().getDrawable(R.drawable.selected_location_tv_border)); LinearLayout currentLL; ll = parentll; if (parentll.getChildAt(parentll.getChildCount() - 1) != null) { parentll.getChildAt(parentll.getChildCount() - 1).measure(0, 0); widthSoFar = (parentll.getChildAt(parentll.getChildCount() - 1).getMeasuredWidth()) + tv.getMeasuredWidth(); } Display display = getActivity().getWindowManager().getDefaultDisplay(); maxWidth = display.getWidth() - 100; // Check if parent Liner Layout has child if (parentll.getChildCount() == 0 || widthSoFar >= maxWidth) { // Create a liner layout and add currentLL = new LinearLayout(mContext); currentLL.setLayoutParams( new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); // currentLL.setGravity(Gravity.LEFT); currentLL.setOrientation(LinearLayout.HORIZONTAL); // vertical parentll.addView(currentLL); } currentLL = (LinearLayout) parentll.getChildAt(parentll.getChildCount() - 1); currentLL.addView(tv); }
/** * Sets the popup colors, when QuickScroll.TYPE_POPUP is selected as type. * * <p> * * @param backgroundcolor the background color of the TextView * @param bordercolor the background color of the border surrounding the TextView * @param textcolor the color of the text */ @SuppressWarnings("deprecation") @SuppressLint("NewApi") public void setPopupColor( final int backgroundcolor, final int bordercolor, final int borderwidthDPI, final int textcolor, float cornerradiusDPI) { final GradientDrawable popupbackground = new GradientDrawable(); popupbackground.setCornerRadius(cornerradiusDPI * getResources().getDisplayMetrics().density); popupbackground.setStroke( (int) (borderwidthDPI * getResources().getDisplayMetrics().density), bordercolor); popupbackground.setColor(backgroundcolor); if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) mScrollIndicatorText.setBackgroundDrawable(popupbackground); else mScrollIndicatorText.setBackground(popupbackground); mScrollIndicatorText.setTextColor(textcolor); }
protected void stopCounter(int restCir, int restBackgroundText, boolean retry) { if (!counterStopped) counterStopped = true; try { imageCir.setAnimation(null); imageCir.setBackgroundDrawable(getResources().getDrawable(restCir)); imageCir.setAnimation( AnimationUtils.loadAnimation(getContext(), R.anim.anim_circle_rotation_2)); } catch (Exception e) { Log.d(TAG, "", e); } try { counterText.setText(""); if (restBackgroundText > 0) counterText.setBackgroundDrawable(getResources().getDrawable(restBackgroundText)); } catch (Exception e) { Log.e(TAG, "", e); } this.retry = retry; }
private void startDrag(Bitmap bm, int x, int y) { stopDrag(); mWindowParams.x = x; mWindowParams.y = y; TextView v = new TextView(context); v.setBackgroundDrawable(new BitmapDrawable(bm)); dragBitmap = bm; mWindowManager = (WindowManager) context.getSystemService("window"); mWindowManager.addView(v, mWindowParams); dragView = v; if (fileManager.multFile) { dragView.setTextSize(35); dragView.setTextColor(Color.RED); dragView.setGravity(Gravity.CENTER); dragView.setText("" + fileManager.getCurrentSelectedCount()); } // else // dragView.setBackgroundResource(R.drawable.list_drag_background); }
void init( Context context, View inputView, int backgroundResource, int bx, int by, CharSequence description, int guide, boolean leftAlign) { bubbleBackground = context.getResources().getDrawable(backgroundResource); x = bx; y = by; width = (int) (inputView.getWidth() * 0.9); this.gravity = Gravity.TOP | Gravity.LEFT; text = new SpannableStringBuilder() .append(description) .append("\n") .append(context.getResources().getText(guide)); this.dismissOnTouch = true; this.dismissOnClose = false; this.inputView = inputView; window = new PopupWindow(context); window.setBackgroundDrawable(null); LayoutInflater inflate = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); textView = (TextView) inflate.inflate(R.layout.bubble_text, null); textView.setBackgroundDrawable(bubbleBackground); textView.setText(text); if (leftAlign) { textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT); } window.setContentView(textView); window.setFocusable(false); window.setTouchable(true); window.setOutsideTouchable(false); }
private void updateColor(int nColor) { mSettingInfo.setBackgroundDrawable(new ColorDrawable(nColor)); mColorSettingInfo.setAlpha(Color.alpha(nColor)); // mSettingInfo.setAlpha(Color.alpha(nColor)); }
public void displayAccounts() { accounts = b2evolution.DB.getAccounts(this); HashMap<?, ?> notificationOptions = b2evolution.DB.getNotificationOptions(this); boolean sound = false, vibrate = false, light = false, taglineValue = false; String tagline = ""; if (notificationOptions != null) { if (notificationOptions.get("sound").toString().equals("1")) { sound = true; } if (notificationOptions.get("vibrate").toString().equals("1")) { vibrate = true; } if (notificationOptions.get("light").toString().equals("1")) { light = true; } if (notificationOptions.get("tagline_flag").toString().equals("1")) { taglineValue = true; } tagline = notificationOptions.get("tagline").toString(); } if (accounts.size() > 0) { ScrollView sv = new ScrollView(this); sv.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); sv.setBackgroundColor(Color.parseColor("#FFFFFFFF")); LinearLayout layout = new LinearLayout(this); layout.setPadding(14, 14, 14, 14); layout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); layout.setOrientation(LinearLayout.VERTICAL); layout.setGravity(Gravity.LEFT); final LinearLayout cbLayout = new LinearLayout(this); cbLayout.setLayoutParams( new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); cbLayout.setOrientation(LinearLayout.VERTICAL); LinearLayout.LayoutParams section1Params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); section1Params.setMargins(0, 0, 0, 20); LinearLayout section1 = new LinearLayout(this); section1.setBackgroundDrawable(getResources().getDrawable(R.drawable.content_bg)); section1.setLayoutParams(section1Params); section1.setOrientation(LinearLayout.VERTICAL); LinearLayout.LayoutParams headerParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); headerParams.setMargins(1, 1, 1, 0); TextView textView = new TextView(this); textView.setLayoutParams(headerParams); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); textView.setTypeface(Typeface.DEFAULT_BOLD); textView.setPadding(0, 4, 0, 4); textView.setShadowLayer(1, 0, 2, Color.parseColor("#FFFFFFFF")); textView.setBackgroundDrawable(getResources().getDrawable(R.drawable.content_bg_header)); textView.setText(" " + getResources().getText(R.string.comment_notifications)); section1.addView(textView); LinearLayout.LayoutParams cbParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); cbParams.setMargins(4, 0, 0, 6); for (int i = 0; i < accounts.size(); i++) { HashMap<?, ?> curHash = (HashMap<?, ?>) accounts.get(i); String curBlogName = curHash.get("blogName").toString(); String accountID = curHash.get("id").toString(); int runService = Integer.valueOf(curHash.get("runService").toString()); accountNames.add(i, curBlogName); final CheckBox checkBox = new CheckBox(this); checkBox.setTextColor(Color.parseColor("#444444")); checkBox.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); checkBox.setText(EscapeUtils.unescapeHtml(curBlogName)); checkBox.setId(Integer.valueOf(accountID)); checkBox.setLayoutParams(cbParams); if (runService == 1) { checkBox.setChecked(true); } cbLayout.addView(checkBox); } if (cbLayout.getChildCount() > 0) { section1.addView(cbLayout); } // add spinner and buttons TextView textView2 = new TextView(this); LinearLayout.LayoutParams labelParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); labelParams.setMargins(8, 0, 0, 0); textView2.setLayoutParams(labelParams); textView2.setTextColor(Color.parseColor("#444444")); textView2.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); textView2.setText(getResources().getText(R.string.notifications_interval)); section1.addView(textView2); final Spinner sInterval = new Spinner(this); LinearLayout.LayoutParams spinnerParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); spinnerParams.setMargins(4, 0, 4, 10); sInterval.setLayoutParams(spinnerParams); ArrayAdapter<Object> sIntervalArrayAdapter = new ArrayAdapter<Object>( this, R.layout.spinner_textview, new String[] { "5 Minutes", "10 Minutes", "15 Minutes", "30 Minutes", "1 Hour", "3 Hours", "6 Hours", "12 Hours", "Daily" }); sIntervalArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); sInterval.setAdapter(sIntervalArrayAdapter); String interval = b2evolution.DB.getInterval(this); if (interval != "") { sInterval.setSelection(sIntervalArrayAdapter.getPosition(interval)); } section1.addView(sInterval); final LinearLayout nOptionsLayout = new LinearLayout(this); nOptionsLayout.setLayoutParams( new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); nOptionsLayout.setOrientation(LinearLayout.VERTICAL); CheckBox soundCB = new CheckBox(this); soundCB.setTag("soundCB"); soundCB.setTextColor(Color.parseColor("#444444")); soundCB.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); soundCB.setText(getResources().getText(R.string.notification_sound)); soundCB.setLayoutParams(cbParams); soundCB.setChecked(sound); nOptionsLayout.addView(soundCB); CheckBox vibrateCB = new CheckBox(this); vibrateCB.setTag("vibrateCB"); vibrateCB.setTextColor(Color.parseColor("#444444")); vibrateCB.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); vibrateCB.setText(getResources().getText(R.string.notification_vibrate)); vibrateCB.setLayoutParams(cbParams); vibrateCB.setChecked(vibrate); nOptionsLayout.addView(vibrateCB); CheckBox lightCB = new CheckBox(this); lightCB.setTag("lightCB"); lightCB.setTextColor(Color.parseColor("#444444")); lightCB.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); lightCB.setText(getResources().getText(R.string.notification_blink)); lightCB.setLayoutParams(cbParams); lightCB.setChecked(light); nOptionsLayout.addView(lightCB); section1.addView(nOptionsLayout); layout.addView(section1); final LinearLayout section2 = new LinearLayout(this); section2.setBackgroundDrawable(getResources().getDrawable(R.drawable.content_bg)); section2.setOrientation(LinearLayout.VERTICAL); LinearLayout.LayoutParams section2Params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); section2Params.setMargins(0, 0, 0, 20); section2.setLayoutParams(section2Params); section2.setPadding(0, 0, 0, 10); TextView section2lbl = new TextView(this); section2lbl.setLayoutParams(headerParams); section2lbl.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); section2lbl.setTypeface(Typeface.DEFAULT_BOLD); section2lbl.setShadowLayer(1, 0, 2, Color.parseColor("#FFFFFFFF")); section2lbl.setPadding(0, 4, 0, 4); section2lbl.setText(" " + getResources().getText(R.string.post_signature)); section2lbl.setBackgroundDrawable(getResources().getDrawable(R.drawable.content_bg_header)); section2.addView(section2lbl); CheckBox taglineCB = new CheckBox(this); taglineCB.setTag("taglineCB"); taglineCB.setTextColor(Color.parseColor("#444444")); taglineCB.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); taglineCB.setText(getResources().getText(R.string.add_tagline)); taglineCB.setLayoutParams(cbParams); taglineCB.setChecked(taglineValue); section2.addView(taglineCB); EditText taglineET = new EditText(this); LinearLayout.LayoutParams taglineParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); taglineParams.setMargins(4, 0, 4, 4); taglineET.setLayoutParams(taglineParams); if (tagline != null) { if (tagline.equals("")) { if (BlackBerryUtils.getInstance().isBlackBerry()) taglineET.setText(getResources().getText(R.string.posted_from_blackberry)); else taglineET.setText(getResources().getText(R.string.posted_from)); } else { taglineET.setText(tagline); } } taglineET.setMinLines(2); section2.addView(taglineET); layout.addView(section2); final LinearLayout section3 = new LinearLayout(this); section3.setOrientation(LinearLayout.HORIZONTAL); section3.setGravity(Gravity.RIGHT); LinearLayout.LayoutParams section3Params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); section3Params.setMargins(0, 0, 0, 20); section3.setLayoutParams(section3Params); final Button cancel = new Button(this); LinearLayout.LayoutParams cancelParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); cancelParams.setMargins(0, 0, 10, 0); cancel.setLayoutParams(cancelParams); cancel.setBackgroundDrawable(getResources().getDrawable(R.drawable.b2evo_button_small)); cancel.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); cancel.setText(getResources().getText(R.string.cancel)); cancel.setOnClickListener( new Button.OnClickListener() { public void onClick(View v) { finish(); } }); section3.addView(cancel); final Button save = new Button(this); save.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT)); save.setBackgroundDrawable(getResources().getDrawable(R.drawable.b2evo_button_small)); save.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); save.setText(getResources().getText(R.string.save)); save.setOnClickListener( new Button.OnClickListener() { public void onClick(View v) { boolean sound = false, vibrate = false, light = false, tagValue = false; checkCtr = 0; int listItemCount = cbLayout.getChildCount(); for (int i = 0; i < listItemCount; i++) { CheckBox cbox = (CheckBox) cbLayout.getChildAt(i); int id = cbox.getId(); if (cbox.isChecked()) { checkCtr++; b2evolution.DB.updateNotificationFlag(id, true); Log.i("CommentService", "Service enabled for " + cbox.getText()); } else { b2evolution.DB.updateNotificationFlag(id, false); } } int noOptionsItemCount = nOptionsLayout.getChildCount(); for (int i = 0; i < noOptionsItemCount; i++) { CheckBox cbox = (CheckBox) nOptionsLayout.getChildAt(i); if (cbox.getTag().equals("soundCB")) { sound = cbox.isChecked(); } else if (cbox.getTag().equals("vibrateCB")) { vibrate = cbox.isChecked(); } else if (cbox.getTag().equals("lightCB")) { light = cbox.isChecked(); } } CheckBox tagFlag = (CheckBox) section2.getChildAt(1); tagValue = tagFlag.isChecked(); EditText taglineET = (EditText) section2.getChildAt(2); String taglineText = taglineET.getText().toString(); b2evolution.DB.updateNotificationSettings( sInterval.getSelectedItem().toString(), sound, vibrate, light, tagValue, taglineText); if (checkCtr > 0) { String updateInterval = sInterval.getSelectedItem().toString(); int UPDATE_INTERVAL = 3600000; // configure time interval if (updateInterval.equals("5 Minutes")) { UPDATE_INTERVAL = 300000; } else if (updateInterval.equals("10 Minutes")) { UPDATE_INTERVAL = 600000; } else if (updateInterval.equals("15 Minutes")) { UPDATE_INTERVAL = 900000; } else if (updateInterval.equals("30 Minutes")) { UPDATE_INTERVAL = 1800000; } else if (updateInterval.equals("1 Hour")) { UPDATE_INTERVAL = 3600000; } else if (updateInterval.equals("3 Hours")) { UPDATE_INTERVAL = 10800000; } else if (updateInterval.equals("6 Hours")) { UPDATE_INTERVAL = 21600000; } else if (updateInterval.equals("12 Hours")) { UPDATE_INTERVAL = 43200000; } else if (updateInterval.equals("Daily")) { UPDATE_INTERVAL = 86400000; } Intent intent = new Intent(Preferences.this, CommentBroadcastReceiver.class); PendingIntent pIntent = PendingIntent.getBroadcast(Preferences.this, 0, intent, 0); AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); alarmManager.setRepeating( AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (5 * 1000), UPDATE_INTERVAL, pIntent); } else { Intent stopIntent = new Intent(Preferences.this, CommentBroadcastReceiver.class); PendingIntent stopPIntent = PendingIntent.getBroadcast(Preferences.this, 0, stopIntent, 0); AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); alarmManager.cancel(stopPIntent); Intent service = new Intent(Preferences.this, CommentService.class); stopService(service); } finish(); } }); section3.addView(save); layout.addView(section3); sv.addView(layout); setContentView(sv); } }
@SuppressWarnings("deprecation") private void init(Context context, int initialColor) { setPadding(UI.dialogMargin, UI.dialogMargin, UI.dialogMargin, UI.dialogMargin); final int eachW = (UI._18sp * 7) >> 1; final boolean smallScreen = (UI.isLowDpiScreen && !UI.isLargeScreen); initialColor = 0xff000000 | (initialColor & 0x00ffffff); hsv = new HSV(); hsv.fromRGB(initialColor); hsvTmp = new HSV(); bmpRect = new Rect(0, 0, 1, 1); this.initialColor = initialColor; currentColor = initialColor; sliderColor = (UI.isAndroidThemeLight() ? 0xff000000 : 0xffffffff); final LinearLayout l = new LinearLayout(context); l.setId(1); l.setWeightSum(2); LayoutParams p = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); p.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE); p.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE); p.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE); addView(l, p); final TextView lbl = new TextView(context); lbl.setBackgroundDrawable(new ColorDrawable(initialColor)); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( LayoutParams.WRAP_CONTENT, smallScreen ? (UI.defaultControlSize) >> 1 : UI.defaultControlSize); lp.weight = 1; lp.rightMargin = UI.controlSmallMargin; l.addView(lbl, lp); bgCurrent = new ColorDrawable(initialColor); lblCurrent = new TextView(context); lblCurrent.setBackgroundDrawable(bgCurrent); lp = new LinearLayout.LayoutParams( LayoutParams.WRAP_CONTENT, smallScreen ? (UI.defaultControlSize) >> 1 : UI.defaultControlSize); lp.weight = 1; lp.leftMargin = UI.controlSmallMargin; l.addView(lblCurrent, lp); final int textSize = (smallScreen ? UI._14sp : UI._18sp); TextView lblTit = new TextView(context); lblTit.setId(2); lblTit.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); lblTit.setSingleLine(); lblTit.setGravity(Gravity.CENTER); lblTit.setText("H"); p = new LayoutParams(eachW, LayoutParams.WRAP_CONTENT); p.topMargin = UI.dialogMargin; p.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE); p.addRule(RelativeLayout.BELOW, 1); addView(lblTit, p); lblTit = new TextView(context); lblTit.setId(3); lblTit.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); lblTit.setSingleLine(); lblTit.setGravity(Gravity.CENTER); lblTit.setText("S"); p = new LayoutParams(eachW, LayoutParams.WRAP_CONTENT); p.topMargin = UI.dialogMargin; p.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE); p.addRule(RelativeLayout.BELOW, 1); addView(lblTit, p); lblTit = new TextView(context); lblTit.setId(4); lblTit.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); lblTit.setSingleLine(); lblTit.setGravity(Gravity.CENTER); lblTit.setText("V"); p = new LayoutParams(eachW, LayoutParams.WRAP_CONTENT); p.topMargin = UI.dialogMargin; p.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE); p.addRule(RelativeLayout.BELOW, 1); addView(lblTit, p); barH = new BgSeekBar(context); barH.setId(5); barH.setMax(360); barH.setValue((int) (hsv.h * 360.0)); barH.setSliderMode(true); barH.setVertical(true); p = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); p.topMargin = UI.dialogMargin; p.leftMargin = ((eachW - UI.defaultControlSize) >> 1); p.addRule(RelativeLayout.ALIGN_LEFT, 2); p.addRule(RelativeLayout.BELOW, 2); p.addRule(RelativeLayout.ABOVE, 6); addView(barH, p); barS = new BgSeekBar(context); barS.setMax(100); barS.setValue((int) (hsv.s * 100.0)); barS.setSliderMode(true); barS.setVertical(true); p = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); p.topMargin = UI.dialogMargin; p.leftMargin = ((eachW - UI.defaultControlSize) >> 1); p.addRule(RelativeLayout.ALIGN_LEFT, 3); p.addRule(RelativeLayout.BELOW, 3); p.addRule(RelativeLayout.ABOVE, 6); addView(barS, p); barV = new BgSeekBar(context); barV.setMax(100); barV.setValue((int) (hsv.v * 100.0)); barV.setSliderMode(true); barV.setVertical(true); p = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); p.topMargin = UI.dialogMargin; p.leftMargin = ((eachW - UI.defaultControlSize) >> 1); p.addRule(RelativeLayout.ALIGN_LEFT, 4); p.addRule(RelativeLayout.BELOW, 4); p.addRule(RelativeLayout.ABOVE, 6); addView(barV, p); txtH = new EditText(context); txtH.setId(6); txtH.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); txtH.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS); txtH.setSingleLine(); txtH.setGravity(Gravity.CENTER); txtH.setText(Integer.toString((int) (hsv.h * 360.0))); p = new LayoutParams(eachW, LayoutParams.WRAP_CONTENT); p.topMargin = UI.dialogMargin; p.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE); p.addRule(RelativeLayout.ABOVE, 7); addView(txtH, p); txtS = new EditText(context); txtS.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); txtS.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS); txtS.setSingleLine(); txtS.setGravity(Gravity.CENTER); txtS.setText(Integer.toString((int) (hsv.s * 100.0))); p = new LayoutParams(eachW, LayoutParams.WRAP_CONTENT); p.topMargin = UI.dialogMargin; p.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE); p.addRule(RelativeLayout.ABOVE, 7); addView(txtS, p); txtV = new EditText(context); txtV.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); txtV.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS); txtV.setSingleLine(); txtV.setGravity(Gravity.CENTER); txtV.setText(Integer.toString((int) (hsv.v * 100.0))); p = new LayoutParams(eachW, LayoutParams.WRAP_CONTENT); p.topMargin = UI.dialogMargin; p.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE); p.addRule(RelativeLayout.ABOVE, 7); addView(txtV, p); txt = new EditText(context); txt.setId(7); txt.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); txt.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS); txt.setSingleLine(); txt.setGravity(Gravity.CENTER); txt.setText(ColorUtils.toHexColor(initialColor)); p = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); p.topMargin = UI.dialogMargin; p.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE); p.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE); p.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE); addView(txt, p); lbl.setOnClickListener(this); barH.setOnBgSeekBarChangeListener(this); barH.setOnBgSeekBarDrawListener(this); barS.setOnBgSeekBarChangeListener(this); barS.setOnBgSeekBarDrawListener(this); barV.setOnBgSeekBarChangeListener(this); barV.setOnBgSeekBarDrawListener(this); txtH.addTextChangedListener(this); txtS.addTextChangedListener(this); txtV.addTextChangedListener(this); txt.addTextChangedListener(this); }
/** * Creates the view. * * @param name the name */ public void createView(String name) { LinearLayout screen2_layout = (LinearLayout) findViewById(R.id.screen2_button_layout); screen2_layout.removeAllViews(); try { SharedPreferences myData = getSharedPreferences("myData", MODE_PRIVATE); Editor edit = myData.edit(); edit.putString("extra_array", nearByPlacesArray.toString()); edit.commit(); } catch (Exception e) { e.printStackTrace(); } // Parsing JSON for (int i = 0; i < nearByPlacesArray.length(); i++) { try { final String title = nearByPlacesArray.getJSONObject(i).getString("name").toString(); String lower_title = title.toLowerCase(); name = name.toLowerCase(); if (!name.equals("all") && !name.equals(lower_title.substring(0, name.length()))) { continue; } final String address = nearByPlacesArray.getJSONObject(i).getString("address").toString(); final String[] placeCords = new String[2]; placeCords[0] = nearByPlacesArray.getJSONObject(i).getString("lat").toString(); placeCords[1] = nearByPlacesArray.getJSONObject(i).getString("lng").toString(); final String distance = calculateDistance(userCords, placeCords); String resourceName = "m" + nearByPlacesArray.getJSONObject(i).getString("subcatid").toString(); int resourceId = this.getResources().getIdentifier(resourceName, "drawable", this.getPackageName()); // ////////////////////////////START MAKING // BUTTON///////////////////////// Typeface face = Typeface.createFromAsset(getAssets(), "fonts/verdana.ttf"); TextView btn = new TextView(this); btn.setText( Html.fromHtml( "<big><b>" + " " + title + "</b></big><br/>" + " " + address + "<br/>" + " " + distance + "")); btn.setTag(title + "_button"); LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1.0f); btn.setLayoutParams(params); btn.setBackgroundDrawable(this.getResources().getDrawable(R.drawable.color_gradient)); Drawable img = null; try { img = getApplicationContext().getResources().getDrawable(resourceId); } catch (Exception e) { e.printStackTrace(); } if (img == null) { resourceName = "city_null"; int resId = this.getResources().getIdentifier(resourceName, "drawable", this.getPackageName()); } resourceName = "city_location"; int resId = this.getResources().getIdentifier(resourceName, "drawable", this.getPackageName()); Drawable img2 = null; try { img2 = getApplicationContext().getResources().getDrawable(resId); } catch (Exception e) { e.printStackTrace(); } btn.setCompoundDrawablesWithIntrinsicBounds(null, null, img, null); btn.setTextColor(Color.GRAY); final int index = i; btn.setOnClickListener( new OnClickListener() { public void onClick(View v) { // Intent mIntent = new Intent(getApplicationContext(), Review.class); SharedPreferences myData = getSharedPreferences("myData", MODE_PRIVATE); Editor myEdit = myData.edit(); try { myEdit.putString("pid", nearByPlacesArray.getJSONObject(index).getString("pid")); myEdit.putInt("index", index); myEdit.commit(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } Intent prevIntent = getIntent(); String callback = prevIntent.getStringExtra("callback"); final int NEARPLACE_CAPTURE_CALLBACK = 3; final int NEARPLACE_SELECT_CALLBACK = 4; /* * Throws exception when callback is null */ try { if (callback.equals("capture")) { setResult(NEARPLACE_CAPTURE_CALLBACK, prevIntent); finish(); } else if (callback.equals("select")) { setResult(NEARPLACE_SELECT_CALLBACK, prevIntent); finish(); } } catch (Exception e) { progg = ProgressDialog.show(NearByPlaces.this, "Please wait!", "Loading...", true); startActivityForResult(mIntent, 0); } } }); screen2_layout.addView(btn); // /////////////////////////////END MAKING // BUTTON///////////////////////////// } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
private void updateLayout(UserOperation op) { if (op == UserOperation.LOGIN) { loginTitle.setTextColor(Color.parseColor("#D95555")); loginTitle.setBackgroundResource(R.mipmap.bg_login_tab); loginTitle.setPadding(16, 16, 16, 16); loginTitle.setGravity(Gravity.CENTER); registerTitle.setTextColor(Color.parseColor("#888888")); registerTitle.setBackgroundDrawable(null); registerTitle.setPadding(16, 16, 16, 16); registerTitle.setGravity(Gravity.CENTER); resetPassword.setTextColor(Color.parseColor("#888888")); resetPassword.setBackgroundDrawable(null); resetPassword.setPadding(16, 16, 16, 16); resetPassword.setGravity(Gravity.CENTER); userNameInput.setVisibility(View.VISIBLE); userPasswordInput.setVisibility(View.VISIBLE); userSchoolInput.setVisibility(View.GONE); userEmailInput.setVisibility(View.GONE); registerButton.setText("登录"); } else if (op == UserOperation.REGISTER) { loginTitle.setTextColor(Color.parseColor("#888888")); loginTitle.setBackgroundDrawable(null); loginTitle.setPadding(16, 16, 16, 16); loginTitle.setGravity(Gravity.CENTER); registerTitle.setTextColor(Color.parseColor("#D95555")); registerTitle.setBackgroundResource(R.mipmap.bg_login_tab); registerTitle.setPadding(16, 16, 16, 16); registerTitle.setGravity(Gravity.CENTER); resetPassword.setTextColor(Color.parseColor("#888888")); resetPassword.setBackgroundDrawable(null); resetPassword.setPadding(16, 16, 16, 16); resetPassword.setGravity(Gravity.CENTER); userNameInput.setVisibility(View.VISIBLE); userPasswordInput.setVisibility(View.VISIBLE); userEmailInput.setVisibility(View.VISIBLE); userSchoolInput.setVisibility(View.VISIBLE); registerButton.setText("注册"); } else { loginTitle.setTextColor(Color.parseColor("#888888")); loginTitle.setBackgroundDrawable(null); loginTitle.setPadding(16, 16, 16, 16); loginTitle.setGravity(Gravity.CENTER); registerTitle.setTextColor(Color.parseColor("#888888")); registerTitle.setBackgroundDrawable(null); registerTitle.setPadding(16, 16, 16, 16); registerTitle.setGravity(Gravity.CENTER); resetPassword.setTextColor(Color.parseColor("#D95555")); resetPassword.setBackgroundResource(R.mipmap.bg_login_tab); resetPassword.setPadding(16, 16, 16, 16); resetPassword.setGravity(Gravity.CENTER); userNameInput.setVisibility(View.GONE); userPasswordInput.setVisibility(View.GONE); userEmailInput.setVisibility(View.VISIBLE); registerButton.setText("找回密码"); } }
@Override public View onCreateView( LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.backup_code_fragment, container, false); Bundle args = getArguments(); mBackupCode = args.getString(ARG_BACKUP_CODE); mMasterKeyIds = args.getLongArray(ARG_MASTER_KEY_IDS); mExportSecret = args.getBoolean(ARG_EXPORT_SECRET); mExecuteBackupOperation = args.getBoolean(ARG_EXECUTE_BACKUP_OPERATION, true); mCodeEditText = new EditText[6]; mCodeEditText[0] = (EditText) view.findViewById(R.id.backup_code_1); mCodeEditText[1] = (EditText) view.findViewById(R.id.backup_code_2); mCodeEditText[2] = (EditText) view.findViewById(R.id.backup_code_3); mCodeEditText[3] = (EditText) view.findViewById(R.id.backup_code_4); mCodeEditText[4] = (EditText) view.findViewById(R.id.backup_code_5); mCodeEditText[5] = (EditText) view.findViewById(R.id.backup_code_6); { TextView[] codeDisplayText = new TextView[6]; codeDisplayText[0] = (TextView) view.findViewById(R.id.backup_code_display_1); codeDisplayText[1] = (TextView) view.findViewById(R.id.backup_code_display_2); codeDisplayText[2] = (TextView) view.findViewById(R.id.backup_code_display_3); codeDisplayText[3] = (TextView) view.findViewById(R.id.backup_code_display_4); codeDisplayText[4] = (TextView) view.findViewById(R.id.backup_code_display_5); codeDisplayText[5] = (TextView) view.findViewById(R.id.backup_code_display_6); // set backup code in code TextViews char[] backupCode = mBackupCode.toCharArray(); for (int i = 0; i < codeDisplayText.length; i++) { codeDisplayText[i].setText(backupCode, i * 5, 4); } // set background to null in TextViews - this will retain padding from EditText style! for (TextView textView : codeDisplayText) { // noinspection deprecation, setBackground(Drawable) is API level >=16 textView.setBackgroundDrawable(null); } } setupEditTextFocusNext(mCodeEditText); setupEditTextSuccessListener(mCodeEditText); mStatusAnimator = (ToolableViewAnimator) view.findViewById(R.id.status_animator); mTitleAnimator = (ToolableViewAnimator) view.findViewById(R.id.title_animator); mCodeFieldsAnimator = (ToolableViewAnimator) view.findViewById(R.id.code_animator); View backupInput = view.findViewById(R.id.button_backup_input); backupInput.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { switchState(BackupCodeState.STATE_INPUT, true); } }); view.findViewById(R.id.button_backup_save) .setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { mShareNotSave = false; startBackup(); } }); view.findViewById(R.id.button_backup_share) .setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { mShareNotSave = true; startBackup(); } }); view.findViewById(R.id.button_backup_back) .setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { FragmentManager fragMan = getFragmentManager(); if (fragMan != null) { fragMan.popBackStack(); } } }); view.findViewById(R.id.button_faq) .setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { showFaq(); } }); return view; }
@Override public boolean setUiBeforShow() { if (style == STYLE_DEFAULT) { widthScale(0.95f); } /** title */ float radius = dp2px(cornerRadius_DP); tv_title.setHeight(dp2px(titleHeight)); tv_title.setBackgroundDrawable( CornerUtils.cornerDrawable( titleBgColor, new float[] {radius, radius, radius, radius, 0, 0, 0, 0})); tv_title.setText(title); tv_title.setTextSize(TypedValue.COMPLEX_UNIT_SP, titleTextSize_SP); tv_title.setTextColor(titleTextColor); tv_title.setVisibility(isTitleShow ? View.VISIBLE : View.GONE); /** title underline */ v_line_title.setLayoutParams( new LayoutParams(LayoutParams.MATCH_PARENT, dp2px(dividerHeight_DP))); v_line_title.setBackgroundColor(dividerColor); v_line_title.setVisibility(isTitleShow ? View.VISIBLE : View.GONE); /** cancel btn */ tv_cancel.setHeight(dp2px(itemHeight_DP)); tv_cancel.setText("取消"); tv_cancel.setTextSize(TypedValue.COMPLEX_UNIT_SP, itemTextSize_SP); tv_cancel.setTextColor(itemTextColor); tv_cancel.setBackgroundDrawable( CornerUtils.listItemSelector(radius, lvBgColor, itemPressColor, 1, 0)); tv_cancel.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { dismiss(); } }); /** listview */ lv.setDivider(new ColorDrawable(dividerColor)); lv.setDividerHeight(dp2px(dividerHeight_DP)); if (isTitleShow) { lv.setBackgroundDrawable( CornerUtils.cornerDrawable( lvBgColor, new float[] {0, 0, 0, 0, radius, radius, radius, radius})); } else { lv.setBackgroundDrawable(CornerUtils.cornerDrawable(lvBgColor, radius)); } if (adapter == null) { adapter = new ListDialogAdapter(); } lv.setAdapter(adapter); lv.setOnItemClickListener( new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (onOperItemClickL != null) { onOperItemClickL.onOperItemClick(parent, view, position, id); } } }); if (isLacShow) lv.setLayoutAnimation(lac); return false; }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.activity_menu, null); drawable = getResources().getDrawable(R.drawable.bg_press); textUserInfo = (TextView) view.findViewById(R.id.txt_userinfo); textFinished = (TextView) view.findViewById(R.id.txt_finish); textUnfinish = (TextView) view.findViewById(R.id.txt_unfinish); textAbout = (TextView) view.findViewById(R.id.txt_about); textSetting = (TextView) view.findViewById(R.id.txt_setting); textExit = (TextView) view.findViewById(R.id.txt_exit); textReturn = (TextView) view.findViewById(R.id.txt_return); textUnfinish.setBackgroundDrawable(drawable); textUserInfo.setOnClickListener( new OnClickListener() { @SuppressWarnings("deprecation") @Override public void onClick(View v) { // TODO Auto-generated method stub if (index == 1) ((SlidingActivity) getActivity()).getSlidingMenu().toggle(); index = 1; drawable = getResources().getDrawable(R.drawable.bg_press); textUserInfo.setBackgroundDrawable(drawable); textFinished.setBackgroundDrawable(null); textUnfinish.setBackgroundDrawable(null); textSetting.setBackgroundDrawable(null); textAbout.setBackgroundDrawable(null); textReturn.setBackgroundDrawable(null); textExit.setBackgroundDrawable(null); FragmentManager fm = ((SlidingActivity) getActivity()).getFragmentManager(); /** @parma replace(被替换的layout,新的fragment) */ fm.beginTransaction().replace(R.id.unfinish, new PersonalInfoFragment()).commit(); ((SlidingActivity) getActivity()).getSlidingMenu().showContent(); } }); textUnfinish.setOnClickListener( new OnClickListener() { @SuppressWarnings("deprecation") @Override public void onClick(View arg0) { // TODO Auto-generated method stub if (index == 2) ((SlidingActivity) getActivity()).getSlidingMenu().toggle(); index = 2; FragmentManager fm = ((SlidingActivity) getActivity()).getFragmentManager(); drawable = getResources().getDrawable(R.drawable.bg_press); textUserInfo.setBackgroundDrawable(null); textFinished.setBackgroundDrawable(null); textUnfinish.setBackgroundDrawable(drawable); textSetting.setBackgroundDrawable(null); textAbout.setBackgroundDrawable(null); textReturn.setBackgroundDrawable(null); textExit.setBackgroundDrawable(null); /** @parma replace(被替换的layout,新的fragment) */ fm.beginTransaction() .replace( R.id.unfinish, unfinishFragment == null ? new UnfinishFragment() : unfinishFragment) .commit(); ((SlidingActivity) getActivity()).getSlidingMenu().showContent(); } }); textFinished.setOnClickListener( new OnClickListener() { @SuppressWarnings("deprecation") @Override public void onClick(View v) { // TODO Auto-generated method stub if (index == 3) ((SlidingActivity) getActivity()).getSlidingMenu().toggle(); index = 3; FragmentManager fm = ((SlidingActivity) getActivity()).getFragmentManager(); fm.beginTransaction() .replace( R.id.unfinish, finishFragment == null ? new FinishFragment() : finishFragment) .addToBackStack(null) .commit(); drawable = getResources().getDrawable(R.drawable.bg_press); textUserInfo.setBackgroundDrawable(null); textFinished.setBackgroundDrawable(drawable); textUnfinish.setBackgroundDrawable(null); textSetting.setBackgroundDrawable(null); textAbout.setBackgroundDrawable(null); textReturn.setBackgroundDrawable(null); textExit.setBackgroundDrawable(null); ((SlidingActivity) getActivity()).getSlidingMenu().showContent(); } }); textReturn.setOnClickListener( new OnClickListener() { @SuppressWarnings("deprecation") @Override public void onClick(View v) { // TODO Auto-generated method stub Editor edit = ((SlidingActivity) getActivity()).sp.edit(); edit.putBoolean("login_in", false); edit.commit(); drawable = getResources().getDrawable(R.drawable.bg_press); textUserInfo.setBackgroundDrawable(null); textFinished.setBackgroundDrawable(null); textUnfinish.setBackgroundDrawable(null); textSetting.setBackgroundDrawable(null); textAbout.setBackgroundDrawable(null); textReturn.setBackgroundDrawable(drawable); textExit.setBackgroundDrawable(null); Intent intent = new Intent(getActivity(), LoginAndRegisterActivity.class); startActivity(intent); getActivity().finish(); } }); textExit.setOnClickListener( new OnClickListener() { @SuppressWarnings("deprecation") @Override public void onClick(View v) { // TODO Auto-generated method stub drawable = getResources().getDrawable(R.drawable.bg_press); textExit.setBackgroundDrawable(drawable); getActivity().showDialog(0x112233); } }); textSetting.setOnClickListener( new OnClickListener() { @SuppressWarnings("deprecation") @Override public void onClick(View v) { // TODO Auto-generated method stub drawable = getResources().getDrawable(R.drawable.bg_press); textUserInfo.setBackgroundDrawable(null); textFinished.setBackgroundDrawable(null); textUnfinish.setBackgroundDrawable(null); textSetting.setBackgroundDrawable(drawable); textAbout.setBackgroundDrawable(null); textReturn.setBackgroundDrawable(null); textExit.setBackgroundDrawable(null); if (index == 4) ((SlidingActivity) getActivity()).getSlidingMenu().toggle(); index = 4; FragmentManager fm = ((SlidingActivity) getActivity()).getFragmentManager(); fm.beginTransaction().replace(R.id.unfinish, new newSettingFragment()).commit(); ((SlidingActivity) getActivity()).getSlidingMenu().showContent(); } }); textAbout.setOnClickListener( new OnClickListener() { @SuppressWarnings("deprecation") @Override public void onClick(View v) { // TODO Auto-generated method stub drawable = getResources().getDrawable(R.drawable.bg_press); textUserInfo.setBackgroundDrawable(null); textFinished.setBackgroundDrawable(null); textUnfinish.setBackgroundDrawable(null); textSetting.setBackgroundDrawable(null); textAbout.setBackgroundDrawable(drawable); textReturn.setBackgroundDrawable(null); textExit.setBackgroundDrawable(null); if (index == 5) ((SlidingActivity) getActivity()).getSlidingMenu().toggle(); index = 5; FragmentManager fm = ((SlidingActivity) getActivity()).getFragmentManager(); fm.beginTransaction().replace(R.id.unfinish, new AboutFragment()).commit(); ((SlidingActivity) getActivity()).getSlidingMenu().showContent(); } }); return view; }