List of usage examples for android.app DatePickerDialog DatePickerDialog
public DatePickerDialog(@NonNull Context context, @Nullable OnDateSetListener listener, int year, int month, int dayOfMonth)
From source file:com.example.carsharing.ShortWayActivity.java
@Override protected Dialog onCreateDialog(int id) { switch (id) { case TIME_DIALOG: return new TimePickerDialog(this, mTimeSetListener, c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE), false);// ww w . j a v a 2 s .co m case DATE_DIALOG: return new DatePickerDialog(this, mDateSetListener, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH)); case TIME_DIALOG1: return new TimePickerDialog(this, mTimeSetListener1, c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE), false); } return null; }
From source file:dev.memento.MementoBrowser.java
@Override protected Dialog onCreateDialog(int id) { Dialog dialog = null;//from w w w. j ava2 s.c om AlertDialog.Builder builder = new AlertDialog.Builder(this); switch (id) { case DIALOG_DATE: dialog = new DatePickerDialog(this, mDateSetListener, mDateChosen.getYear(), mDateChosen.getMonth() - 1, mDateChosen.getDay()); break; case DIALOG_ERROR: builder = new AlertDialog.Builder(this); builder.setMessage("error message").setCancelable(false).setPositiveButton("OK", null); dialog = builder.create(); break; case DIALOG_MEMENTO_YEARS: builder = new AlertDialog.Builder(this); final CharSequence[] years = mMementos.getAllYears(); // Select the year of the Memento currently displayed int selectedYear = -1; for (int i = 0; i < years.length; i++) { if (mDateDisplayed.getYear() == Integer.parseInt(years[i].toString())) { selectedYear = i; break; } } builder.setSingleChoiceItems(years, selectedYear, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { dialog.dismiss(); mSelectedYear = Integer.parseInt(years[item].toString()); showDialog(DIALOG_MEMENTO_DATES); } }); dialog = builder.create(); // Cause the dialog to be freed whenever it is dismissed. // This is necessary because the items are dynamic. dialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface arg0) { removeDialog(DIALOG_MEMENTO_YEARS); } }); break; case DIALOG_MEMENTO_DATES: builder = new AlertDialog.Builder(this); final CharSequence[] dates; if (mSelectedYear == 0) dates = mMementos.getAllDates(); else dates = mMementos.getDatesForYear(mSelectedYear); Log.d(LOG_TAG, "Number of dates = " + dates.length); // This shouldn't happen, but just in case. if (dates.length == 0) { showToast("No Mementos to select from."); return null; } int selected = -1; // Select the radio button for the current Memento if it's in the selected year. if (mSelectedYear == 0 || mSelectedYear == mDateDisplayed.getYear()) { int index = mMementos.getIndex(mDateDisplayed); if (index < 0) Log.d(LOG_TAG, "Could not find Memento in the list with date " + mDateDisplayed); else mMementos.setCurrentIndex(index); Memento m = mMementos.getCurrent(); if (m != null) { for (int i = 0; i < dates.length; i++) { if (m.getDateTime().dateAndTimeFormatted().equals(dates[i])) { selected = i; break; } } } else Log.d(LOG_TAG, "There is no current Memento"); } Log.d(LOG_TAG, "Selected index = " + selected); builder.setSingleChoiceItems(dates, selected, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { dialog.dismiss(); int index = mMementos.getIndex(dates[item].toString()); Memento m = mMementos.get(index); if (m == null) { Log.e(LOG_TAG, "Could not find Memento with date " + mDateChosen + "."); displayError("The date selected could not be accessed. Please select another."); } else { // Display this Memento Log.d(LOG_TAG, "index for [" + dates[item] + "] is " + index); SimpleDateTime d = m.getDateTime(); setChosenDate(d); if (index == mMementos.getCurrentIndex()) { showToast("Memento is already displayed."); } else { mMementos.setCurrentIndex(index); showToast("Time travelling to " + mDateChosen.dateFormatted()); // Find the Memento URL for the selected date mDateDisplayed = new SimpleDateTime(mDateChosen); String redirectUrl = m.getUrl(); Log.d(LOG_TAG, "Sending browser to " + redirectUrl); mWebview.loadUrl(redirectUrl); setEnableForNextPrevButtons(); } } } }); dialog = builder.create(); // Cause the dialog to be freed whenever it is dismissed. // This is necessary because the items are dynamic. I couldn't find // a better way to solve this problem. dialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface arg0) { removeDialog(DIALOG_MEMENTO_DATES); } }); break; case DIALOG_HELP: Context context = getApplicationContext(); LayoutInflater inflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.about_dialog, null); builder.setView(layout); builder.setPositiveButton("OK", null); dialog = builder.create(); break; } return dialog; }
From source file:rta.ae.sharekni.RegisterNewTest.java
@Override protected Dialog onCreateDialog(int id) { if (id == DILOG_ID) { DatePickerDialog dp = new DatePickerDialog(this, dPickerListener, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH)); d = dp.getDatePicker();/*w w w . j a va 2s. c o m*/ d.updateDate(year_x, month_x, day_x); d.setMaxDate(cal.getTimeInMillis()); return dp; } return null; }
From source file:org.totschnig.myexpenses.activity.ExpenseEdit.java
@Override protected Dialog onCreateDialog(int id) { switch (id) { case DATE_DIALOG_ID: boolean brokenSamsungDevice = isBrokenSamsungDevice(); @SuppressLint("InlinedApi") Context context = brokenSamsungDevice ? new ContextThemeWrapper(this, MyApplication.getThemeType() == MyApplication.ThemeType.dark ? android.R.style.Theme_Holo_Dialog : android.R.style.Theme_Holo_Light_Dialog) : this; int year = mCalendar.get(Calendar.YEAR); int month = mCalendar.get(Calendar.MONTH); int day = mCalendar.get(Calendar.DAY_OF_MONTH); DatePickerDialog datePickerDialog = new DatePickerDialog(context, mDateSetListener, year, month, day); if (brokenSamsungDevice) { datePickerDialog.setTitle(""); datePickerDialog.updateDate(year, month, day); }//from w ww . j a v a2 s . co m return datePickerDialog; case TIME_DIALOG_ID: return new TimePickerDialog(this, mTimeSetListener, mCalendar.get(Calendar.HOUR_OF_DAY), mCalendar.get(Calendar.MINUTE), android.text.format.DateFormat.is24HourFormat(this)); } return null; }
From source file:org.telegram.ui.ChannelAdminLogActivity.java
@Override public View createView(Context context) { if (chatMessageCellsCache.isEmpty()) { for (int a = 0; a < 8; a++) { chatMessageCellsCache.add(new ChatMessageCell(context)); }/* w w w.ja v a 2 s. c o m*/ } searchWas = false; hasOwnBackground = true; Theme.createChatResources(context, false); actionBar.setAddToContainer(false); actionBar.setOccupyStatusBar(Build.VERSION.SDK_INT >= 21 && !AndroidUtilities.isTablet()); actionBar.setBackButtonDrawable(new BackDrawable(false)); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override public void onItemClick(final int id) { if (id == -1) { finishFragment(); } } }); avatarContainer = new ChatAvatarContainer(context, null, false); avatarContainer.setOccupyStatusBar(!AndroidUtilities.isTablet()); actionBar.addView(avatarContainer, 0, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 56, 0, 40, 0)); ActionBarMenu menu = actionBar.createMenu(); searchItem = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true) .setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() { @Override public void onSearchCollapse() { searchQuery = ""; avatarContainer.setVisibility(View.VISIBLE); if (searchWas) { searchWas = false; loadMessages(true); } /*highlightMessageId = Integer.MAX_VALUE; updateVisibleRows(); scrollToLastMessage(false); */ updateBottomOverlay(); } @Override public void onSearchExpand() { avatarContainer.setVisibility(View.GONE); updateBottomOverlay(); } @Override public void onSearchPressed(EditText editText) { searchWas = true; searchQuery = editText.getText().toString(); loadMessages(true); //updateSearchButtons(0, 0, 0); } }); searchItem.setSearchFieldHint(LocaleController.getString("Search", R.string.Search)); avatarContainer.setEnabled(false); avatarContainer.setTitle(currentChat.title); avatarContainer.setSubtitle(LocaleController.getString("EventLogAllEvents", R.string.EventLogAllEvents)); avatarContainer.setChatAvatar(currentChat); fragmentView = new SizeNotifierFrameLayout(context) { @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject(); if (messageObject != null && messageObject.isRoundVideo() && messageObject.eventId != 0 && messageObject.getDialogId() == -currentChat.id) { MediaController.getInstance().setTextureView(createTextureView(false), aspectRatioFrameLayout, roundVideoContainer, true); } } @Override protected boolean drawChild(Canvas canvas, View child, long drawingTime) { boolean result = super.drawChild(canvas, child, drawingTime); if (child == actionBar && parentLayout != null) { parentLayout.drawHeaderShadow(canvas, actionBar.getVisibility() == VISIBLE ? actionBar.getMeasuredHeight() : 0); } return result; } @Override protected boolean isActionBarVisible() { return actionBar.getVisibility() == VISIBLE; } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int allHeight; int widthSize = MeasureSpec.getSize(widthMeasureSpec); int heightSize = MeasureSpec.getSize(heightMeasureSpec); setMeasuredDimension(widthSize, heightSize); heightSize -= getPaddingTop(); measureChildWithMargins(actionBar, widthMeasureSpec, 0, heightMeasureSpec, 0); int actionBarHeight = actionBar.getMeasuredHeight(); if (actionBar.getVisibility() == VISIBLE) { heightSize -= actionBarHeight; } int keyboardSize = getKeyboardHeight(); int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { View child = getChildAt(i); if (child == null || child.getVisibility() == GONE || child == actionBar) { continue; } if (child == chatListView || child == progressView) { int contentWidthSpec = MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY); int contentHeightSpec = MeasureSpec.makeMeasureSpec( Math.max(AndroidUtilities.dp(10), heightSize - AndroidUtilities.dp(48 + 2)), MeasureSpec.EXACTLY); child.measure(contentWidthSpec, contentHeightSpec); } else if (child == emptyViewContainer) { int contentWidthSpec = MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY); int contentHeightSpec = MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.EXACTLY); child.measure(contentWidthSpec, contentHeightSpec); } else { measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0); } } } @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { final int count = getChildCount(); for (int i = 0; i < count; i++) { final View child = getChildAt(i); if (child.getVisibility() == GONE) { continue; } final LayoutParams lp = (LayoutParams) child.getLayoutParams(); final int width = child.getMeasuredWidth(); final int height = child.getMeasuredHeight(); int childLeft; int childTop; int gravity = lp.gravity; if (gravity == -1) { gravity = Gravity.TOP | Gravity.LEFT; } final int absoluteGravity = gravity & Gravity.HORIZONTAL_GRAVITY_MASK; final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK; switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: childLeft = (r - l - width) / 2 + lp.leftMargin - lp.rightMargin; break; case Gravity.RIGHT: childLeft = r - width - lp.rightMargin; break; case Gravity.LEFT: default: childLeft = lp.leftMargin; } switch (verticalGravity) { case Gravity.TOP: childTop = lp.topMargin + getPaddingTop(); if (child != actionBar && actionBar.getVisibility() == VISIBLE) { childTop += actionBar.getMeasuredHeight(); } break; case Gravity.CENTER_VERTICAL: childTop = (b - t - height) / 2 + lp.topMargin - lp.bottomMargin; break; case Gravity.BOTTOM: childTop = (b - t) - height - lp.bottomMargin; break; default: childTop = lp.topMargin; } if (child == emptyViewContainer) { childTop -= AndroidUtilities.dp(24) - (actionBar.getVisibility() == VISIBLE ? actionBar.getMeasuredHeight() / 2 : 0); } else if (child == actionBar) { childTop -= getPaddingTop(); } child.layout(childLeft, childTop, childLeft + width, childTop + height); } updateMessagesVisisblePart(); notifyHeightChanged(); } }; contentView = (SizeNotifierFrameLayout) fragmentView; contentView.setOccupyStatusBar(!AndroidUtilities.isTablet()); contentView.setBackgroundImage(Theme.getCachedWallpaper(), Theme.isWallpaperMotion()); emptyViewContainer = new FrameLayout(context); emptyViewContainer.setVisibility(View.INVISIBLE); contentView.addView(emptyViewContainer, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER)); emptyViewContainer.setOnTouchListener((v, event) -> true); emptyView = new TextView(context); emptyView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); emptyView.setGravity(Gravity.CENTER); emptyView.setTextColor(Theme.getColor(Theme.key_chat_serviceText)); emptyView.setBackgroundDrawable( Theme.createRoundRectDrawable(AndroidUtilities.dp(10), Theme.getServiceMessageColor())); emptyView.setPadding(AndroidUtilities.dp(16), AndroidUtilities.dp(16), AndroidUtilities.dp(16), AndroidUtilities.dp(16)); emptyViewContainer.addView(emptyView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER, 16, 0, 16, 0)); chatListView = new RecyclerListView(context) { @Override public boolean drawChild(Canvas canvas, View child, long drawingTime) { boolean result = super.drawChild(canvas, child, drawingTime); if (child instanceof ChatMessageCell) { ChatMessageCell chatMessageCell = (ChatMessageCell) child; ImageReceiver imageReceiver = chatMessageCell.getAvatarImage(); if (imageReceiver != null) { int top = child.getTop(); if (chatMessageCell.isPinnedBottom()) { ViewHolder holder = chatListView.getChildViewHolder(child); if (holder != null) { holder = chatListView .findViewHolderForAdapterPosition(holder.getAdapterPosition() + 1); if (holder != null) { imageReceiver.setImageY(-AndroidUtilities.dp(1000)); imageReceiver.draw(canvas); return result; } } } if (chatMessageCell.isPinnedTop()) { ViewHolder holder = chatListView.getChildViewHolder(child); if (holder != null) { while (true) { holder = chatListView .findViewHolderForAdapterPosition(holder.getAdapterPosition() - 1); if (holder != null) { top = holder.itemView.getTop(); if (!(holder.itemView instanceof ChatMessageCell) || !((ChatMessageCell) holder.itemView).isPinnedTop()) { break; } } else { break; } } } } int y = child.getTop() + chatMessageCell.getLayoutHeight(); int maxY = chatListView.getHeight() - chatListView.getPaddingBottom(); if (y > maxY) { y = maxY; } if (y - AndroidUtilities.dp(48) < top) { y = top + AndroidUtilities.dp(48); } imageReceiver.setImageY(y - AndroidUtilities.dp(44)); imageReceiver.draw(canvas); } } return result; } }; chatListView.setOnItemClickListener((view, position) -> createMenu(view)); chatListView.setTag(1); chatListView.setVerticalScrollBarEnabled(true); chatListView.setAdapter(chatAdapter = new ChatActivityAdapter(context)); chatListView.setClipToPadding(false); chatListView.setPadding(0, AndroidUtilities.dp(4), 0, AndroidUtilities.dp(3)); chatListView.setItemAnimator(null); chatListView.setLayoutAnimation(null); chatLayoutManager = new LinearLayoutManager(context) { @Override public boolean supportsPredictiveItemAnimations() { return false; } @Override public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) { LinearSmoothScrollerMiddle linearSmoothScroller = new LinearSmoothScrollerMiddle( recyclerView.getContext()); linearSmoothScroller.setTargetPosition(position); startSmoothScroll(linearSmoothScroller); } }; chatLayoutManager.setOrientation(LinearLayoutManager.VERTICAL); chatLayoutManager.setStackFromEnd(true); chatListView.setLayoutManager(chatLayoutManager); contentView.addView(chatListView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); chatListView.setOnScrollListener(new RecyclerView.OnScrollListener() { private float totalDy = 0; private final int scrollValue = AndroidUtilities.dp(100); @Override public void onScrollStateChanged(RecyclerView recyclerView, int newState) { if (newState == RecyclerView.SCROLL_STATE_DRAGGING) { scrollingFloatingDate = true; checkTextureViewPosition = true; } else if (newState == RecyclerView.SCROLL_STATE_IDLE) { scrollingFloatingDate = false; checkTextureViewPosition = false; hideFloatingDateView(true); } } @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { chatListView.invalidate(); if (dy != 0 && scrollingFloatingDate && !currentFloatingTopIsNotMessage) { if (floatingDateView.getTag() == null) { if (floatingDateAnimation != null) { floatingDateAnimation.cancel(); } floatingDateView.setTag(1); floatingDateAnimation = new AnimatorSet(); floatingDateAnimation.setDuration(150); floatingDateAnimation.playTogether(ObjectAnimator.ofFloat(floatingDateView, "alpha", 1.0f)); floatingDateAnimation.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if (animation.equals(floatingDateAnimation)) { floatingDateAnimation = null; } } }); floatingDateAnimation.start(); } } checkScrollForLoad(true); updateMessagesVisisblePart(); } }); if (scrollToPositionOnRecreate != -1) { chatLayoutManager.scrollToPositionWithOffset(scrollToPositionOnRecreate, scrollToOffsetOnRecreate); scrollToPositionOnRecreate = -1; } progressView = new FrameLayout(context); progressView.setVisibility(View.INVISIBLE); contentView.addView(progressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT)); progressView2 = new View(context); progressView2.setBackgroundResource(R.drawable.system_loader); progressView2.getBackground().setColorFilter(Theme.colorFilter); progressView.addView(progressView2, LayoutHelper.createFrame(36, 36, Gravity.CENTER)); progressBar = new RadialProgressView(context); progressBar.setSize(AndroidUtilities.dp(28)); progressBar.setProgressColor(Theme.getColor(Theme.key_chat_serviceText)); progressView.addView(progressBar, LayoutHelper.createFrame(32, 32, Gravity.CENTER)); floatingDateView = new ChatActionCell(context); floatingDateView.setAlpha(0.0f); contentView.addView(floatingDateView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 4, 0, 0)); contentView.addView(actionBar); bottomOverlayChat = new FrameLayout(context) { @Override public void onDraw(Canvas canvas) { int bottom = Theme.chat_composeShadowDrawable.getIntrinsicHeight(); Theme.chat_composeShadowDrawable.setBounds(0, 0, getMeasuredWidth(), bottom); Theme.chat_composeShadowDrawable.draw(canvas); canvas.drawRect(0, bottom, getMeasuredWidth(), getMeasuredHeight(), Theme.chat_composeBackgroundPaint); } }; bottomOverlayChat.setWillNotDraw(false); bottomOverlayChat.setPadding(0, AndroidUtilities.dp(3), 0, 0); contentView.addView(bottomOverlayChat, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 51, Gravity.BOTTOM)); bottomOverlayChat.setOnClickListener(view -> { if (getParentActivity() == null) { return; } AdminLogFilterAlert adminLogFilterAlert = new AdminLogFilterAlert(getParentActivity(), currentFilter, selectedAdmins, currentChat.megagroup); adminLogFilterAlert.setCurrentAdmins(admins); adminLogFilterAlert.setAdminLogFilterAlertDelegate((filter, admins) -> { currentFilter = filter; selectedAdmins = admins; if (currentFilter != null || selectedAdmins != null) { avatarContainer.setSubtitle( LocaleController.getString("EventLogSelectedEvents", R.string.EventLogSelectedEvents)); } else { avatarContainer.setSubtitle( LocaleController.getString("EventLogAllEvents", R.string.EventLogAllEvents)); } loadMessages(true); }); showDialog(adminLogFilterAlert); }); bottomOverlayChatText = new TextView(context); bottomOverlayChatText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15); bottomOverlayChatText.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); bottomOverlayChatText.setTextColor(Theme.getColor(Theme.key_chat_fieldOverlayText)); bottomOverlayChatText.setText(LocaleController.getString("SETTINGS", R.string.SETTINGS).toUpperCase()); bottomOverlayChat.addView(bottomOverlayChatText, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER)); bottomOverlayImage = new ImageView(context); bottomOverlayImage.setImageResource(R.drawable.log_info); bottomOverlayImage.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_fieldOverlayText), PorterDuff.Mode.MULTIPLY)); bottomOverlayImage.setScaleType(ImageView.ScaleType.CENTER); bottomOverlayChat.addView(bottomOverlayImage, LayoutHelper.createFrame(48, 48, Gravity.RIGHT | Gravity.TOP, 3, 0, 0, 0)); bottomOverlayImage.setOnClickListener(v -> { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); if (currentChat.megagroup) { builder.setMessage(AndroidUtilities.replaceTags( LocaleController.getString("EventLogInfoDetail", R.string.EventLogInfoDetail))); } else { builder.setMessage(AndroidUtilities.replaceTags(LocaleController .getString("EventLogInfoDetailChannel", R.string.EventLogInfoDetailChannel))); } builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null); builder.setTitle(LocaleController.getString("EventLogInfoTitle", R.string.EventLogInfoTitle)); showDialog(builder.create()); }); searchContainer = new FrameLayout(context) { @Override public void onDraw(Canvas canvas) { int bottom = Theme.chat_composeShadowDrawable.getIntrinsicHeight(); Theme.chat_composeShadowDrawable.setBounds(0, 0, getMeasuredWidth(), bottom); Theme.chat_composeShadowDrawable.draw(canvas); canvas.drawRect(0, bottom, getMeasuredWidth(), getMeasuredHeight(), Theme.chat_composeBackgroundPaint); } }; searchContainer.setWillNotDraw(false); searchContainer.setVisibility(View.INVISIBLE); searchContainer.setFocusable(true); searchContainer.setFocusableInTouchMode(true); searchContainer.setClickable(true); searchContainer.setPadding(0, AndroidUtilities.dp(3), 0, 0); contentView.addView(searchContainer, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 51, Gravity.BOTTOM)); /*searchUpButton = new ImageView(context); searchUpButton.setScaleType(ImageView.ScaleType.CENTER); searchUpButton.setImageResource(R.drawable.search_up); searchUpButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_searchPanelIcons), PorterDuff.Mode.MULTIPLY)); searchContainer.addView(searchUpButton, LayoutHelper.createFrame(48, 48)); searchUpButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { MessagesSearchQuery.searchMessagesInChat(null, dialog_id, mergeDialogId, classGuid, 1); } }); searchDownButton = new ImageView(context); searchDownButton.setScaleType(ImageView.ScaleType.CENTER); searchDownButton.setImageResource(R.drawable.search_down); searchDownButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_searchPanelIcons), PorterDuff.Mode.MULTIPLY)); searchContainer.addView(searchDownButton, LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.TOP, 48, 0, 0, 0)); searchDownButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { MessagesSearchQuery.searchMessagesInChat(null, dialog_id, mergeDialogId, classGuid, 2); } });*/ searchCalendarButton = new ImageView(context); searchCalendarButton.setScaleType(ImageView.ScaleType.CENTER); searchCalendarButton.setImageResource(R.drawable.search_calendar); searchCalendarButton.setColorFilter(new PorterDuffColorFilter( Theme.getColor(Theme.key_chat_searchPanelIcons), PorterDuff.Mode.MULTIPLY)); searchContainer.addView(searchCalendarButton, LayoutHelper.createFrame(48, 48, Gravity.RIGHT | Gravity.TOP)); searchCalendarButton.setOnClickListener(view -> { if (getParentActivity() == null) { return; } AndroidUtilities.hideKeyboard(searchItem.getSearchField()); Calendar calendar = Calendar.getInstance(); int year = calendar.get(Calendar.YEAR); int monthOfYear = calendar.get(Calendar.MONTH); int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH); try { DatePickerDialog dialog = new DatePickerDialog(getParentActivity(), (view1, year1, month, dayOfMonth1) -> { Calendar calendar1 = Calendar.getInstance(); calendar1.clear(); calendar1.set(year1, month, dayOfMonth1); int date = (int) (calendar1.getTime().getTime() / 1000); loadMessages(true); }, year, monthOfYear, dayOfMonth); final DatePicker datePicker = dialog.getDatePicker(); datePicker.setMinDate(1375315200000L); datePicker.setMaxDate(System.currentTimeMillis()); dialog.setButton(DialogInterface.BUTTON_POSITIVE, LocaleController.getString("JumpToDate", R.string.JumpToDate), dialog); dialog.setButton(DialogInterface.BUTTON_NEGATIVE, LocaleController.getString("Cancel", R.string.Cancel), (dialog12, which) -> { }); if (Build.VERSION.SDK_INT >= 21) { dialog.setOnShowListener(dialog1 -> { int count = datePicker.getChildCount(); for (int a = 0; a < count; a++) { View child = datePicker.getChildAt(a); ViewGroup.LayoutParams layoutParams = child.getLayoutParams(); layoutParams.width = LayoutHelper.MATCH_PARENT; child.setLayoutParams(layoutParams); } }); } showDialog(dialog); } catch (Exception e) { FileLog.e(e); } }); searchCountText = new SimpleTextView(context); searchCountText.setTextColor(Theme.getColor(Theme.key_chat_searchPanelText)); searchCountText.setTextSize(15); searchCountText.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); searchContainer.addView(searchCountText, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.CENTER_VERTICAL, 108, 0, 0, 0)); chatAdapter.updateRows(); if (loading && messages.isEmpty()) { progressView.setVisibility(View.VISIBLE); chatListView.setEmptyView(null); } else { progressView.setVisibility(View.INVISIBLE); chatListView.setEmptyView(emptyViewContainer); } updateEmptyPlaceholder(); return fragmentView; }
From source file:com.example.carsharing.CommuteActivity.java
@Override protected Dialog onCreateDialog(int id) { switch (id) { case TIME_DIALOG: return new TimePickerDialog(this, mTimeSetListener, c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE), false);//w w w.j a v a 2 s .c om case DATE_DIALOG: return new DatePickerDialog(this, mDateSetListener, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH)); case DATE_DIALOG01: return new DatePickerDialog(this, mDateSetListener1, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH)); case TIME_DIALOG01: return new TimePickerDialog(this, mTimeSetListener1, c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE), false); } return null; }
From source file:com.abc.driver.MainActivity.java
public void chooseDate2(View v) { mTSDtv = (TextView) findViewById(R.id.truck_shipper_date_tv); Calendar calendar = Calendar.getInstance(); Dialog dialog = null;/*from w w w . j av a2 s . c o m*/ DatePickerDialog.OnDateSetListener dateListener = new DatePickerDialog.OnDateSetListener() { public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { String tmpMonthOfYear, tmpDayofMonth; if (monthOfYear < 9) { tmpMonthOfYear = "0" + (monthOfYear + 1); } else { tmpMonthOfYear = "" + (monthOfYear + 1); } if (dayOfMonth < 9) { tmpDayofMonth = "0" + dayOfMonth; } else { tmpDayofMonth = "" + dayOfMonth; } mTruckShipperDate = year + "-" + tmpMonthOfYear + "-" + tmpDayofMonth; mTSDtv.setText(mTruckShipperDate); } }; dialog = new DatePickerDialog(this, dateListener, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)); dialog.show(); }
From source file:foam.starwisp.StarwispBuilder.java
public void Update(final StarwispActivity ctx, final String ctxname, JSONArray arr) { String type = ""; Integer tid = 0;/*w ww . j ava2 s. c om*/ String token = ""; try { type = arr.getString(0); tid = arr.getInt(1); token = arr.getString(2); } catch (JSONException e) { Log.e("starwisp", "Error parsing update arguments for " + ctxname + " " + arr.toString() + e.toString()); } final Integer id = tid; //Log.i("starwisp", "Update: "+type+" "+id+" "+token); try { // non widget commands if (token.equals("toast")) { Toast msg = Toast.makeText(ctx.getBaseContext(), arr.getString(3), Toast.LENGTH_SHORT); LinearLayout linearLayout = (LinearLayout) msg.getView(); View child = linearLayout.getChildAt(0); TextView messageTextView = (TextView) child; messageTextView.setTextSize(arr.getInt(4)); msg.show(); return; } if (token.equals("play-sound")) { String name = arr.getString(3); if (name.equals("ping")) { MediaPlayer mp = MediaPlayer.create(ctx, R.raw.ping); mp.start(); } if (name.equals("active")) { MediaPlayer mp = MediaPlayer.create(ctx, R.raw.active); mp.start(); } } if (token.equals("soundfile-start-recording")) { String filename = arr.getString(3); m_SoundManager.StartRecording(filename); } if (token.equals("soundfile-stop-recording")) { m_SoundManager.StopRecording(); } if (token.equals("soundfile-start-playback")) { String filename = arr.getString(3); m_SoundManager.StartPlaying(filename); } if (token.equals("soundfile-stop-playback")) { m_SoundManager.StopPlaying(); } if (token.equals("vibrate")) { Vibrator v = (Vibrator) ctx.getSystemService(Context.VIBRATOR_SERVICE); v.vibrate(arr.getInt(3)); } if (type.equals("replace-fragment")) { int ID = arr.getInt(1); String name = arr.getString(2); Fragment fragment = ActivityManager.GetFragment(name); FragmentTransaction ft = ctx.getSupportFragmentManager().beginTransaction(); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); //ft.setCustomAnimations( R.animator.fragment_slide_left_enter, // R.animator.fragment_slide_right_exit); //ft.setCustomAnimations( // R.animator.card_flip_right_in, R.animator.card_flip_right_out, // R.animator.card_flip_left_in, R.animator.card_flip_left_out); ft.replace(ID, fragment); ft.addToBackStack(null); ft.commit(); return; } if (token.equals("dialog-fragment")) { FragmentManager fm = ctx.getSupportFragmentManager(); final int ID = arr.getInt(3); final JSONArray lp = arr.getJSONArray(4); final String name = arr.getString(5); final Dialog dialog = new Dialog(ctx); dialog.setTitle("Title..."); LinearLayout inner = new LinearLayout(ctx); inner.setId(ID); inner.setLayoutParams(BuildLayoutParams(lp)); dialog.setContentView(inner); // Fragment fragment = ActivityManager.GetFragment(name); // FragmentTransaction fragmentTransaction = ctx.getSupportFragmentManager().beginTransaction(); // fragmentTransaction.add(ID,fragment); // fragmentTransaction.commit(); dialog.show(); /* DialogFragment df = new DialogFragment() { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { LinearLayout inner = new LinearLayout(ctx); inner.setId(ID); inner.setLayoutParams(BuildLayoutParams(lp)); return inner; } @Override public Dialog onCreateDialog(Bundle savedInstanceState) { Dialog ret = super.onCreateDialog(savedInstanceState); Log.i("starwisp","MAKINGDAMNFRAGMENT"); Fragment fragment = ActivityManager.GetFragment(name); FragmentTransaction fragmentTransaction = ctx.getSupportFragmentManager().beginTransaction(); fragmentTransaction.add(1,fragment); fragmentTransaction.commit(); return ret; } }; df.show(ctx.getFragmentManager(), "foo"); */ } if (token.equals("time-picker-dialog")) { final Calendar c = Calendar.getInstance(); int hour = c.get(Calendar.HOUR_OF_DAY); int minute = c.get(Calendar.MINUTE); // Create a new instance of TimePickerDialog and return it TimePickerDialog d = new TimePickerDialog(ctx, null, hour, minute, true); d.show(); return; } ; if (token.equals("view")) { //ctx.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse())); File f = new File(arr.getString(3)); Uri fileUri = Uri.fromFile(f); Intent myIntent = new Intent(android.content.Intent.ACTION_VIEW); String extension = android.webkit.MimeTypeMap.getFileExtensionFromUrl(arr.getString(3)); String mimetype = android.webkit.MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); myIntent.setDataAndType(fileUri, mimetype); ctx.startActivity(myIntent); return; } if (token.equals("make-directory")) { File file = new File(((StarwispActivity) ctx).m_AppDir + arr.getString(3)); file.mkdirs(); return; } if (token.equals("list-files")) { final String name = arr.getString(3); File file = new File(((StarwispActivity) ctx).m_AppDir + arr.getString(5)); // todo, should probably call callback with empty list if (file != null) { File list[] = file.listFiles(); if (list != null) { String code = "("; for (int i = 0; i < list.length; i++) { code += " \"" + list[i].getName() + "\""; } code += ")"; DialogCallback(ctx, ctxname, name, code); } } return; } if (token.equals("gps-start")) { final String name = arr.getString(3); if (m_LocationManager == null) { m_LocationManager = (LocationManager) ctx.getSystemService(Context.LOCATION_SERVICE); m_GPS = new DorisLocationListener(m_LocationManager); } m_GPS.Start((StarwispActivity) ctx, name, this, arr.getInt(5), arr.getInt(6)); return; } if (token.equals("sensors-get")) { final String name = arr.getString(3); if (m_SensorHandler == null) { m_SensorHandler = new SensorHandler((StarwispActivity) ctx, this); } m_SensorHandler.GetSensors((StarwispActivity) ctx, name, this); return; } if (token.equals("sensors-start")) { final String name = arr.getString(3); final JSONArray requested_json = arr.getJSONArray(5); ArrayList<Integer> requested = new ArrayList<Integer>(); try { for (int i = 0; i < requested_json.length(); i++) { requested.add(requested_json.getInt(i)); } } catch (JSONException e) { Log.e("starwisp", "Error parsing data in sensors start " + e.toString()); } // start it up... if (m_SensorHandler == null) { m_SensorHandler = new SensorHandler((StarwispActivity) ctx, this); } m_SensorHandler.StartSensors((StarwispActivity) ctx, name, this, requested); return; } if (token.equals("sensors-stop")) { if (m_SensorHandler != null) { m_SensorHandler.StopSensors(); } return; } if (token.equals("walk-draggable")) { final String name = arr.getString(3); int iid = arr.getInt(5); DialogCallback(ctx, ctxname, name, WalkDraggable(ctx, name, ctxname, iid).replace("\\", "")); return; } if (token.equals("delayed")) { final String name = arr.getString(3); final int d = arr.getInt(5); Runnable timerThread = new Runnable() { public void run() { DialogCallback(ctx, ctxname, name, ""); } }; m_Handler.removeCallbacksAndMessages(null); m_Handler.postDelayed(timerThread, d); return; } if (token.equals("network-connect")) { final String name = arr.getString(3); final String ssid = arr.getString(5); m_NetworkManager.Start(ssid, (StarwispActivity) ctx, name, this); return; } if (token.equals("http-request")) { Log.i("starwisp", "http-request called"); if (m_NetworkManager.state == NetworkManager.State.CONNECTED) { Log.i("starwisp", "attempting http request"); final String name = arr.getString(3); final String url = arr.getString(5); m_NetworkManager.StartRequestThread(url, "normal", "", name); } return; } if (token.equals("http-post")) { Log.i("starwisp", "http-post called"); if (m_NetworkManager.state == NetworkManager.State.CONNECTED) { Log.i("starwisp", "attempting http request"); final String name = arr.getString(3); final String url = arr.getString(5); final String data = arr.getString(6); m_NetworkManager.StartRequestThread(url, "post", data, name); } return; } if (token.equals("http-upload")) { if (m_NetworkManager.state == NetworkManager.State.CONNECTED) { Log.i("starwisp", "attempting http ul request"); final String filename = arr.getString(4); final String url = arr.getString(5); m_NetworkManager.StartRequestThread(url, "upload", "", filename); } return; } if (token.equals("http-download")) { if (m_NetworkManager.state == NetworkManager.State.CONNECTED) { Log.i("starwisp", "attempting http dl request"); final String filename = arr.getString(4); final String url = arr.getString(5); m_NetworkManager.StartRequestThread(url, "download", "", filename); } return; } if (token.equals("take-photo")) { photo(ctx, arr.getString(3), arr.getInt(4)); } if (token.equals("bluetooth")) { final String name = arr.getString(3); m_Bluetooth.Start((StarwispActivity) ctx, name, this); return; } if (token.equals("bluetooth-send")) { m_Bluetooth.Write(arr.getString(3)); } if (token.equals("process-image-in-place")) { BitmapCache.ProcessInPlace(arr.getString(3)); } if (token.equals("send-mail")) { final String to[] = new String[1]; to[0] = arr.getString(3); final String subject = arr.getString(4); final String body = arr.getString(5); JSONArray attach = arr.getJSONArray(6); ArrayList<String> paths = new ArrayList<String>(); for (int a = 0; a < attach.length(); a++) { Log.i("starwisp", attach.getString(a)); paths.add(attach.getString(a)); } email(ctx, to[0], "", subject, body, paths); } if (token.equals("date-picker-dialog")) { final Calendar c = Calendar.getInstance(); int day = c.get(Calendar.DAY_OF_MONTH); int month = c.get(Calendar.MONTH); int year = c.get(Calendar.YEAR); final String name = arr.getString(3); // Create a new instance of TimePickerDialog and return it DatePickerDialog d = new DatePickerDialog(ctx, new DatePickerDialog.OnDateSetListener() { public void onDateSet(DatePicker view, int year, int month, int day) { DialogCallback(ctx, ctxname, name, day + " " + month + " " + year); } }, year, month, day); d.show(); return; } ; if (token.equals("alert-dialog")) { final String name = arr.getString(3); final String msg = arr.getString(5); DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { int result = 0; if (which == DialogInterface.BUTTON_POSITIVE) result = 1; DialogCallback(ctx, ctxname, name, "" + result); } }; AlertDialog.Builder builder = new AlertDialog.Builder(ctx); builder.setMessage(msg).setPositiveButton("Yes", dialogClickListener) .setNegativeButton("No", dialogClickListener).show(); return; } if (token.equals("ok-dialog")) { final String name = arr.getString(3); final String msg = arr.getString(5); DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { int result = 0; if (which == DialogInterface.BUTTON_POSITIVE) result = 1; DialogCallback(ctx, ctxname, name, "" + result); } }; AlertDialog.Builder builder = new AlertDialog.Builder(ctx); builder.setMessage(msg).setPositiveButton("Ok", dialogClickListener).show(); return; } if (token.equals("start-activity")) { ActivityManager.StartActivity(ctx, arr.getString(3), arr.getInt(4), arr.getString(5)); return; } if (token.equals("start-activity-goto")) { ActivityManager.StartActivityGoto(ctx, arr.getString(3), arr.getString(4)); return; } if (token.equals("finish-activity")) { ctx.setResult(arr.getInt(3)); ctx.finish(); return; } /////////////////////////////////////////////////////////// if (id == 0) { Log.i("starwisp", "Zero ID, aborting..."); return; } // now try and find the widget final View vv = ctx.findViewById(id); if (vv == null) { Log.i("starwisp", "Can't find widget : " + id); return; } // tokens that work on everything if (token.equals("hide")) { vv.setVisibility(View.GONE); return; } if (token.equals("show")) { vv.setVisibility(View.VISIBLE); return; } // only tested on spinners if (token.equals("disabled")) { vv.setAlpha(0.3f); //vv.getSelectedView().setEnabled(false); vv.setEnabled(false); return; } if (token.equals("enabled")) { vv.setAlpha(1.0f); //vv.getSelectedView().setEnabled(true); vv.setEnabled(true); return; } if (token.equals("animate")) { JSONArray trans = arr.getJSONArray(3); final TranslateAnimation animation = new TranslateAnimation(getPixelsFromDp(ctx, trans.getInt(0)), getPixelsFromDp(ctx, trans.getInt(1)), getPixelsFromDp(ctx, trans.getInt(2)), getPixelsFromDp(ctx, trans.getInt(3))); animation.setDuration(1000); animation.setFillAfter(false); animation.setInterpolator(new AnticipateOvershootInterpolator(1.0f)); animation.setAnimationListener(new AnimationListener() { @Override public void onAnimationEnd(Animation animation) { vv.clearAnimation(); Log.i("starwisp", "animation end"); ((ViewManager) vv.getParent()).removeView(vv); //LayoutParams lp = new LayoutParams(imageView.getWidth(), imageView.getHeight()); //lp.setMargins(50, 100, 0, 0); //imageView.setLayoutParams(lp); } @Override public void onAnimationRepeat(Animation animation) { } @Override public void onAnimationStart(Animation animation) { Log.i("starwisp", "animation start"); } }); vv.startAnimation(animation); return; } // tokens that work on everything if (token.equals("set-enabled")) { Log.i("starwisp", "set-enabled called..."); vv.setEnabled(arr.getInt(3) == 1); vv.setClickable(arr.getInt(3) == 1); if (vv.getBackground() != null) { if (arr.getInt(3) == 0) { //vv.setBackgroundColor(0x00000000); vv.getBackground().setColorFilter(0x20000000, PorterDuff.Mode.MULTIPLY); } else { vv.getBackground().setColorFilter(null); } } return; } if (token.equals("background-colour")) { JSONArray col = arr.getJSONArray(3); if (type.equals("linear-layout")) { vv.setBackgroundColor(Color.argb(col.getInt(3), col.getInt(0), col.getInt(1), col.getInt(2))); } else { //vv.setBackgroundColor(); vv.getBackground().setColorFilter( Color.argb(col.getInt(3), col.getInt(0), col.getInt(1), col.getInt(2)), PorterDuff.Mode.MULTIPLY); } vv.invalidate(); return; } // special cases if (type.equals("linear-layout")) { //Log.i("starwisp","linear-layout update id: "+id); StarwispLinearLayout.Update(this, (LinearLayout) vv, token, ctx, ctxname, arr); return; } if (type.equals("relative-layout")) { StarwispRelativeLayout.Update(this, (RelativeLayout) vv, token, ctx, ctxname, arr); return; } if (type.equals("draggable")) { LinearLayout v = (LinearLayout) vv; if (token.equals("contents")) { v.removeAllViews(); JSONArray children = arr.getJSONArray(3); for (int i = 0; i < children.length(); i++) { Build(ctx, ctxname, new JSONArray(children.getString(i)), v); } } if (token.equals("contents-add")) { JSONArray children = arr.getJSONArray(3); for (int i = 0; i < children.length(); i++) { Build(ctx, ctxname, new JSONArray(children.getString(i)), v); } } } if (type.equals("button-grid")) { LinearLayout horiz = (LinearLayout) vv; if (token.equals("grid-buttons")) { horiz.removeAllViews(); JSONArray params = arr.getJSONArray(3); String buttontype = params.getString(0); int height = params.getInt(1); int textsize = params.getInt(2); LayoutParams lp = BuildLayoutParams(params.getJSONArray(3)); final JSONArray buttons = params.getJSONArray(4); final int count = buttons.length(); int vertcount = 0; LinearLayout vert = null; for (int i = 0; i < count; i++) { JSONArray button = buttons.getJSONArray(i); if (vertcount == 0) { vert = new LinearLayout(ctx); vert.setId(0); vert.setOrientation(LinearLayout.VERTICAL); horiz.addView(vert); } vertcount = (vertcount + 1) % height; if (buttontype.equals("button")) { Button b = new Button(ctx); b.setId(button.getInt(0)); b.setText(button.getString(1)); b.setTextSize(textsize); b.setLayoutParams(lp); b.setTypeface(((StarwispActivity) ctx).m_Typeface); final String fn = params.getString(5); b.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { CallbackArgs(ctx, ctxname, id, "" + v.getId() + " #t"); } }); vert.addView(b); } else if (buttontype.equals("toggle")) { ToggleButton b = new ToggleButton(ctx); b.setId(button.getInt(0)); b.setText(button.getString(1)); b.setTextSize(textsize); b.setLayoutParams(lp); b.setTypeface(((StarwispActivity) ctx).m_Typeface); final String fn = params.getString(5); b.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String arg = "#f"; if (((ToggleButton) v).isChecked()) arg = "#t"; CallbackArgs(ctx, ctxname, id, "" + v.getId() + " " + arg); } }); vert.addView(b); } else if (buttontype.equals("single")) { ToggleButton b = new ToggleButton(ctx); b.setId(button.getInt(0)); b.setText(button.getString(1)); b.setTextSize(textsize); b.setLayoutParams(lp); b.setTypeface(((StarwispActivity) ctx).m_Typeface); final String fn = params.getString(5); b.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { try { for (int i = 0; i < count; i++) { JSONArray button = buttons.getJSONArray(i); int bid = button.getInt(0); if (bid != v.getId()) { ToggleButton tb = (ToggleButton) ctx.findViewById(bid); tb.setChecked(false); } } } catch (JSONException e) { Log.e("starwisp", "Error parsing on click data " + e.toString()); } CallbackArgs(ctx, ctxname, id, "" + v.getId() + " #t"); } }); vert.addView(b); } } } } /* if (type.equals("grid-layout")) { GridLayout v = (GridLayout)vv; if (token.equals("contents")) { v.removeAllViews(); JSONArray children = arr.getJSONArray(3); for (int i=0; i<children.length(); i++) { Build(ctx,ctxname,new JSONArray(children.getString(i)), v); } } } */ if (type.equals("view-pager")) { ViewPager v = (ViewPager) vv; if (token.equals("switch")) { v.setCurrentItem(arr.getInt(3)); } if (token.equals("pages")) { final JSONArray items = arr.getJSONArray(3); v.setAdapter(new FragmentPagerAdapter(ctx.getSupportFragmentManager()) { @Override public int getCount() { return items.length(); } @Override public Fragment getItem(int position) { try { String fragname = items.getString(position); return ActivityManager.GetFragment(fragname); } catch (JSONException e) { Log.e("starwisp", "Error parsing pages data " + e.toString()); } return null; } }); } } if (type.equals("image-view")) { ImageView v = (ImageView) vv; if (token.equals("image")) { int iid = ctx.getResources().getIdentifier(arr.getString(3), "drawable", ctx.getPackageName()); v.setImageResource(iid); } if (token.equals("external-image")) { v.setImageBitmap(BitmapCache.Load(arr.getString(3))); } return; } if (type.equals("text-view") || type.equals("debug-text-view")) { TextView v = (TextView) vv; if (token.equals("text")) { if (type.equals("debug-text-view")) { //v.setMovementMethod(new ScrollingMovementMethod()); } v.setText(Html.fromHtml(arr.getString(3)), BufferType.SPANNABLE); // v.invalidate(); } if (token.equals("file")) { v.setText(LoadData(arr.getString(3))); } return; } if (type.equals("edit-text")) { EditText v = (EditText) vv; if (token.equals("text")) { v.setText(arr.getString(3)); } if (token.equals("request-focus")) { v.requestFocus(); InputMethodManager imm = (InputMethodManager) ctx .getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(v, InputMethodManager.SHOW_IMPLICIT); } return; } if (type.equals("button")) { Button v = (Button) vv; if (token.equals("text")) { v.setText(arr.getString(3)); } if (token.equals("listener")) { final String fn = arr.getString(3); v.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { m_Scheme.eval("(" + fn + ")"); } }); } return; } if (type.equals("toggle-button")) { ToggleButton v = (ToggleButton) vv; if (token.equals("text")) { v.setText(arr.getString(3)); return; } if (token.equals("checked")) { if (arr.getInt(3) == 0) v.setChecked(false); else v.setChecked(true); return; } if (token.equals("listener")) { final String fn = arr.getString(3); v.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { m_Scheme.eval("(" + fn + ")"); } }); } return; } if (type.equals("canvas")) { StarwispCanvas v = (StarwispCanvas) vv; if (token.equals("drawlist")) { v.SetDrawList(arr.getJSONArray(3)); } return; } if (type.equals("camera-preview")) { final CameraPreview v = (CameraPreview) vv; if (token.equals("take-picture")) { final String path = ((StarwispActivity) ctx).m_AppDir + arr.getString(3); v.TakePicture(new PictureCallback() { public void onPictureTaken(byte[] input, Camera camera) { Bitmap original = BitmapFactory.decodeByteArray(input, 0, input.length); Bitmap resized = Bitmap.createScaledBitmap(original, PHOTO_WIDTH, PHOTO_HEIGHT, true); ByteArrayOutputStream blob = new ByteArrayOutputStream(); resized.compress(Bitmap.CompressFormat.JPEG, 100, blob); String datetime = getDateTime(); String filename = path + datetime + ".jpg"; SaveData(filename, blob.toByteArray()); v.Shutdown(); ctx.finish(); } }); } // don't shut the activity down and use provided path if (token.equals("take-picture-cont")) { final String path = ((StarwispActivity) ctx).m_AppDir + arr.getString(3); Log.i("starwisp", "take-picture-cont fired"); v.TakePicture(new PictureCallback() { public void onPictureTaken(byte[] input, Camera camera) { Log.i("starwisp", "on picture taken..."); // the version used by the uav app Bitmap original = BitmapFactory.decodeByteArray(input, 0, input.length); //Bitmap resized = Bitmap.createScaledBitmap(original, PHOTO_WIDTH, PHOTO_HEIGHT, true); ByteArrayOutputStream blob = new ByteArrayOutputStream(); original.compress(Bitmap.CompressFormat.JPEG, 95, blob); original.recycle(); String filename = path; Log.i("starwisp", path); SaveData(filename, blob.toByteArray()); // burn gps into exif data if (m_GPS.currentLocation != null) { double latitude = m_GPS.currentLocation.getLatitude(); double longitude = m_GPS.currentLocation.getLongitude(); try { ExifInterface exif = new ExifInterface(filename); exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE, GPS.convert(latitude)); exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE_REF, GPS.latitudeRef(latitude)); exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, GPS.convert(longitude)); exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF, GPS.longitudeRef(longitude)); exif.saveAttributes(); } catch (IOException e) { Log.i("starwisp", "Couldn't open " + filename + " to add exif data: ioexception caught."); } } v.TakenPicture(); } }); } if (token.equals("shutdown")) { v.Shutdown(); } return; } if (type.equals("seek-bar")) { SeekBar v = new SeekBar(ctx); if (token.equals("max")) { // android seekbar bug workaround int p = v.getProgress(); v.setMax(0); v.setProgress(0); v.setMax(arr.getInt(3)); v.setProgress(1000); // not working.... :( } } if (type.equals("spinner")) { Spinner v = (Spinner) vv; if (token.equals("selection")) { v.setSelection(arr.getInt(3)); } if (token.equals("array")) { final JSONArray items = arr.getJSONArray(3); ArrayList<String> spinnerArray = new ArrayList<String>(); for (int i = 0; i < items.length(); i++) { spinnerArray.add(items.getString(i)); } ArrayAdapter spinnerArrayAdapter = new ArrayAdapter<String>(ctx, R.layout.spinner_item, spinnerArray) { public View getView(int position, View convertView, ViewGroup parent) { View v = super.getView(position, convertView, parent); ((TextView) v).setTypeface(((StarwispActivity) ctx).m_Typeface); return v; } }; spinnerArrayAdapter.setDropDownViewResource(R.layout.spinner_layout); v.setAdapter(spinnerArrayAdapter); final int wid = id; // need to update for new values v.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> a, View v, int pos, long id) { CallbackArgs(ctx, ctxname, wid, "" + pos); } public void onNothingSelected(AdapterView<?> v) { } }); } return; } if (type.equals("draw-map")) { DrawableMap v = m_DMaps.get(id); if (v != null) { if (token.equals("polygons")) { v.UpdateFromJSON(arr.getJSONArray(3)); } if (token.equals("centre")) { JSONArray tokens = arr.getJSONArray(3); v.Centre(tokens.getDouble(0), tokens.getDouble(1), tokens.getInt(2)); } if (token.equals("layout")) { v.m_parent.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3))); } } else { Log.e("starwisp", "Asked to update a drawmap which doesn't exist"); } } } catch (JSONException e) { Log.e("starwisp", "Error parsing builder data " + e.toString()); Log.e("starwisp", "type:" + type + " id:" + id + " token:" + token); } }
From source file:com.abeo.tia.noordin.ProcessCaseProperty.java
@Override public void onClick(View v) { // TODO Auto-generated method stub if (v == details_btn) { Intent to_purchaser = new Intent(ProcessCaseProperty.this, ProcessCaseDetails.class); startActivity(to_purchaser);//from w w w. j a v a 2s .co m } if (v == purchaser_btn) { Intent to_purchaser = new Intent(ProcessCaseProperty.this, ProcessCasePurchaser.class); startActivity(to_purchaser); } if (v == vendor_btn) { Intent to_vendor = new Intent(ProcessCaseProperty.this, ProcessCaseVendor.class); startActivity(to_vendor); } if (v == property_btn) { Intent to_loan_pricipal = new Intent(ProcessCaseProperty.this, ProcessCaseProperty.class); startActivity(to_loan_pricipal); } if (v == loan_principal_btn) { Intent to_loan_pricipal = new Intent(ProcessCaseProperty.this, ProcessCaseLoanPrincipal.class); startActivity(to_loan_pricipal); } if (v == loan_subsidary_btn) { Intent to_loan_subsidiary = new Intent(ProcessCaseProperty.this, ProcesscaseLoanSubsidiary.class); startActivity(to_loan_subsidiary); } if (v == process_btn) { Intent to_loan_subsidiary = new Intent(ProcessCaseProperty.this, ProcessCaseProcessTab.class); startActivity(to_loan_subsidiary); } if (v == title_search) { new DatePickerDialog(ProcessCaseProperty.this, title_search1, myCalendar.get(Calendar.YEAR), myCalendar.get(Calendar.MONTH), myCalendar.get(Calendar.DAY_OF_MONTH)).show(); } if (v == date_submit_consent) { new DatePickerDialog(ProcessCaseProperty.this, date_submit_consent1, myCalendar.get(Calendar.YEAR), myCalendar.get(Calendar.MONTH), myCalendar.get(Calendar.DAY_OF_MONTH)).show(); } if (v == date_receive_consent) { new DatePickerDialog(ProcessCaseProperty.this, date_receive_consent1, myCalendar.get(Calendar.YEAR), myCalendar.get(Calendar.MONTH), myCalendar.get(Calendar.DAY_OF_MONTH)).show(); } if (v == date14_a) { new DatePickerDialog(ProcessCaseProperty.this, date14_a1, myCalendar.get(Calendar.YEAR), myCalendar.get(Calendar.MONTH), myCalendar.get(Calendar.DAY_OF_MONTH)).show(); } if (v == redemption_date) { new DatePickerDialog(ProcessCaseProperty.this, redemption_date1, myCalendar.get(Calendar.YEAR), myCalendar.get(Calendar.MONTH), myCalendar.get(Calendar.DAY_OF_MONTH)).show(); } if (v == receipt_date) { new DatePickerDialog(ProcessCaseProperty.this, receipt_date1, myCalendar.get(Calendar.YEAR), myCalendar.get(Calendar.MONTH), myCalendar.get(Calendar.DAY_OF_MONTH)).show(); } if (v == date_of_return) { new DatePickerDialog(ProcessCaseProperty.this, date_of_return1, myCalendar.get(Calendar.YEAR), myCalendar.get(Calendar.MONTH), myCalendar.get(Calendar.DAY_OF_MONTH)).show(); } if (v == walkin) { Intent i = new Intent(ProcessCaseProperty.this, WalkInActivity.class); startActivity(i); } if (v == confirm_btn) { try { confirm_values(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:de.ub0r.android.websms.WebSMS.java
@Override protected final Dialog onCreateDialog(final int id) { AlertDialog.Builder builder;/*from www . j a v a 2s.c o m*/ switch (id) { case DIALOG_CUSTOMSENDER: builder = new AlertDialog.Builder(this); builder.setTitle(R.string.custom_sender); builder.setCancelable(true); final EditText et = new EditText(this); builder.setView(et); builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog, final int id) { WebSMS.lastCustomSender = et.getText().toString(); } }); builder.setNegativeButton(android.R.string.cancel, null); return builder.create(); case DIALOG_SENDLATER_DATE: Calendar c = Calendar.getInstance(); return new DatePickerDialog(this, this, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH)); case DIALOG_SENDLATER_TIME: c = Calendar.getInstance(); return new MyTimePickerDialog(this, this, c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE), true); case DIALOG_EMO: return this.createEmoticonsDialog(); default: return null; } }