List of usage examples for android.app Activity setContentView
public void setContentView(View view)
From source file:org.solovyev.android.calculator.ActivityUi.java
@Override public void onCreate(@Nonnull Activity activity) { super.onCreate(activity); if (activity instanceof CalculatorEventListener) { Locator.getInstance().getCalculator().addCalculatorEventListener((CalculatorEventListener) activity); }/*w w w . j av a 2 s.c o m*/ activity.setContentView(layoutId); final View root = activity.findViewById(R.id.main_layout); if (root != null) { processButtons(activity, root); fixFonts(root); addHelpInfo(activity, root); } }
From source file:com.apptentive.android.sdk.module.engagement.interaction.view.survey.SurveyInteractionView.java
@Override public void doOnCreate(final Activity activity, Bundle savedInstanceState) { if (savedInstanceState != null) { surveySubmitted = savedInstanceState.getBoolean(KEY_SURVEY_SUBMITTED, false); }//from w w w. j a v a 2 s .co m if (interaction == null || surveySubmitted) { activity.finish(); return; } activity.setContentView(R.layout.apptentive_survey); // Hide branding if needed. final View branding = activity.findViewById(R.id.apptentive_branding_view); if (branding != null) { if (Configuration.load(activity).isHideBranding(activity)) { branding.setVisibility(View.GONE); } } TextView title = (TextView) activity.findViewById(R.id.title); title.setFocusable(true); title.setFocusableInTouchMode(true); title.setText(interaction.getName()); String descriptionText = interaction.getDescription(); if (descriptionText != null) { TextView description = (TextView) activity.findViewById(R.id.description); description.setText(descriptionText); description.setVisibility(View.VISIBLE); } final Button send = (Button) activity.findViewById(R.id.send); send.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Util.hideSoftKeyboard(activity, view); surveySubmitted = true; if (interaction.isShowSuccessMessage() && interaction.getSuccessMessage() != null) { SurveyThankYouDialog dialog = new SurveyThankYouDialog(activity); dialog.setMessage(interaction.getSuccessMessage()); dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialogInterface) { activity.finish(); } }); dialog.show(); } else { activity.finish(); } EngagementModule.engageInternal(activity, interaction, EVENT_SUBMIT, data.toString()); ApptentiveDatabase.getInstance(activity).addPayload(new SurveyResponse(interaction, surveyState)); Log.d("Survey Submitted."); callListener(true); cleanup(); } }); LinearLayout questions = (LinearLayout) activity.findViewById(R.id.questions); questions.removeAllViews(); // Then render all the questions for (final Question question : interaction.getQuestions()) { if (question.getType() == Question.QUESTION_TYPE_SINGLELINE) { TextSurveyQuestionView textQuestionView = new TextSurveyQuestionView(activity, surveyState, (SinglelineQuestion) question); textQuestionView.setOnSurveyQuestionAnsweredListener(new OnSurveyQuestionAnsweredListener() { public void onAnswered() { sendMetricForQuestion(activity, question); send.setEnabled(isSurveyValid()); } }); questions.addView(textQuestionView); } else if (question.getType() == Question.QUESTION_TYPE_MULTICHOICE) { MultichoiceSurveyQuestionView multichoiceQuestionView = new MultichoiceSurveyQuestionView(activity, surveyState, (MultichoiceQuestion) question); multichoiceQuestionView.setOnSurveyQuestionAnsweredListener(new OnSurveyQuestionAnsweredListener() { public void onAnswered() { sendMetricForQuestion(activity, question); send.setEnabled(isSurveyValid()); } }); questions.addView(multichoiceQuestionView); } else if (question.getType() == Question.QUESTION_TYPE_MULTISELECT) { MultiselectSurveyQuestionView multiselectQuestionView = new MultiselectSurveyQuestionView(activity, surveyState, (MultiselectQuestion) question); multiselectQuestionView.setOnSurveyQuestionAnsweredListener(new OnSurveyQuestionAnsweredListener() { public void onAnswered() { sendMetricForQuestion(activity, question); send.setEnabled(isSurveyValid()); } }); questions.addView(multiselectQuestionView); } } send.setEnabled(isSurveyValid()); // Force the top of the survey to be shown first. title.requestFocus(); }
From source file:com.mimo.service.api.MimoOauth2Client.java
/** * Instantiate a webview and allows the user to login to the Api form within * the application/* w w w . j a v a 2 s .com*/ * * @param p_view * : Calling view * * @param p_activity * : Calling Activity reference **/ @SuppressLint("SetJavaScriptEnabled") public void login(View p_view, Activity p_activity) { final Activity m_activity; m_activity = p_activity; String m_url = this.m_api.getAuthUrl(); WebView m_webview = new WebView(p_view.getContext()); m_webview.getSettings().setJavaScriptEnabled(true); m_webview.setVisibility(View.VISIBLE); m_activity.setContentView(m_webview); m_webview.requestFocus(View.FOCUS_DOWN); /** * Open the softkeyboard of the device to input the text in form which * loads in webview. */ m_webview.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View p_v, MotionEvent p_event) { switch (p_event.getAction()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_UP: if (!p_v.hasFocus()) { p_v.requestFocus(); } break; } return false; } }); /** * Show the progressbar in the title of the activity untill the page * loads the give url. */ m_webview.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView p_view, int p_newProgress) { ((Activity) m_context).setProgress(p_newProgress * 100); ((Activity) m_context).setTitle(MimoAPIConstants.DIALOG_TEXT_LOADING); if (p_newProgress == 100) ((Activity) m_context).setTitle(m_context.getString(R.string.app_name)); } }); m_webview.setWebViewClient(new WebViewClient() { @Override public void onPageStarted(WebView p_view, String p_url, Bitmap p_favicon) { } @Override public void onReceivedHttpAuthRequest(WebView p_view, HttpAuthHandler p_handler, String p_url, String p_realm) { p_handler.proceed(MimoAPIConstants.USERNAME, MimoAPIConstants.PASSWORD); } public void onPageFinished(WebView p_view, String p_url) { if (MimoAPIConstants.DEBUG) { Log.d(TAG, "Page Url = " + p_url); } if (p_url.contains("?code=")) { if (p_url.indexOf("code=") != -1) { String[] m_urlSplit = p_url.split("="); String m_tempString1 = m_urlSplit[1]; if (MimoAPIConstants.DEBUG) { Log.d(TAG, "TempString1 = " + m_tempString1); } String[] m_urlSplit1 = m_tempString1.split("&"); String m_code = m_urlSplit1[0]; if (MimoAPIConstants.DEBUG) { Log.d(TAG, "code = " + m_code); } MimoOauth2Client.this.m_code = m_code; Thread m_thread = new Thread() { public void run() { String m_token = requesttoken(MimoOauth2Client.this.m_code); Log.d(TAG, "Token = " + m_token); Intent m_navigateIntent = new Intent(m_activity, MimoTransactions.class); m_navigateIntent.putExtra(MimoAPIConstants.KEY_TOKEN, m_token); m_activity.startActivity(m_navigateIntent); } }; m_thread.start(); } else { if (MimoAPIConstants.DEBUG) { Log.d(TAG, "going in else"); } } } else if (p_url.contains(MimoAPIConstants.URL_KEY_TOKEN)) { if (p_url.indexOf(MimoAPIConstants.URL_KEY_TOKEN) != -1) { String[] m_urlSplit = p_url.split("="); final String m_token = m_urlSplit[1]; Thread m_thread = new Thread() { public void run() { Intent m_navigateIntent = new Intent(m_activity, MimoTransactions.class); m_navigateIntent.putExtra(MimoAPIConstants.KEY_TOKEN, m_token); m_activity.startActivity(m_navigateIntent); } }; m_thread.start(); } } }; }); m_webview.loadUrl(m_url); }
From source file:com.googlecode.eyesfree.testing.BaseAccessibilityInstrumentationTestCase.java
/** * Calls {@link android.app.Activity#setContentView} with the specified * layout resource and waits for a layout pass. * <p>//from w w w . j av a 2 s .c o m * An initial layout pass is required for * {@link android.view.accessibility.AccessibilityNodeInfo#isVisibleToUser} to return the correct * value. * * @param layoutResID Resource ID to be passed to * {@link android.app.Activity#setContentView}. */ protected void setContentView(final int layoutResID) { final Activity activity = getActivity(); try { runTestOnUiThread(new Runnable() { @Override public void run() { activity.setContentView(layoutResID); } }); waitForAccessibilityIdleSync(); waitForEventQueueSync(); } catch (Throwable e) { e.printStackTrace(); } }
From source file:ca.mymenuapp.ui.debug.DebugAppContainer.java
@Override public ViewGroup get(final Activity activity, MyMenuApp app) { this.app = app; this.activity = activity; drawerContext = activity;//from w w w.j a v a 2 s . c o m activity.setContentView(R.layout.debug_activity_frame); // Manually find the debug drawer and inflate the drawer layout inside of it. ViewGroup drawer = findById(activity, R.id.debug_drawer); LayoutInflater.from(drawerContext).inflate(R.layout.debug_drawer_content, drawer); // Inject after inflating the drawer layout so its views are available to inject. ButterKnife.inject(this, activity); // Set up the contextual actions to watch views coming in and out of the content area. Set<ContextualDebugActions.DebugAction<?>> debugActions = Collections.emptySet(); ContextualDebugActions contextualActions = new ContextualDebugActions(this, debugActions); content.setOnHierarchyChangeListener(HierarchyTreeChangeListener.wrap(contextualActions)); drawerLayout.setDrawerShadow(R.drawable.debug_drawer_shadow, Gravity.END); drawerLayout.setDrawerListener(new DrawerLayout.SimpleDrawerListener() { @Override public void onDrawerOpened(View drawerView) { refreshPicassoStats(); } }); // If you have not seen the debug drawer before, show it with a message if (!seenDebugDrawer.get()) { drawerLayout.postDelayed(new Runnable() { @Override public void run() { drawerLayout.openDrawer(Gravity.END); Toast.makeText(activity, R.string.debug_drawer_welcome, Toast.LENGTH_LONG).show(); } }, 1000); seenDebugDrawer.set(true); } setupNetworkSection(); setupUserInterfaceSection(); setupBuildSection(); setupDeviceSection(); setupPicassoSection(); return content; }
From source file:org.chronotext.MobileTest.Bridge.java
public Bridge(Activity activity) { super(activity); // ---//from w w w . j a va 2s . c o m switch (testMode) { case GLVIEW_ATTACHED_AND_VISIBLE_AT_START: hidden = false; detached = false; break; case GLVIEW_ATTACHED_AND_HIDDEN_AT_START: hidden = true; detached = false; break; default: case GLVIEW_NOT_ATTACHED_AT_START: hidden = false; detached = true; break; } hasRootView = CAN_BE_HIDDEN || CAN_BE_DETACHED || hidden || detached; // --- setViewProperties(new GLView.Properties().setEGLContextClientVersion(1).setPreserveEGLContextOnPause(true)); if (hasRootView) { rootView = new RelativeLayout(activity); rootView.setBackgroundColor(Color.YELLOW); activity.setContentView(rootView); } if (!detached) { if (hidden) { getView().setVisibility(View.GONE); } if (hasRootView) { rootView.addView(getView()); } else { activity.setContentView(getView()); } } // --- overlayView = new RelativeLayout(activity); activity.addContentView(overlayView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); button1 = addButton(100, 100, 1); button2 = addButton(100, 200, 2); refreshButtons(); }
From source file:com.apptentive.android.sdk.module.messagecenter.view.MessageCenterActivityContent.java
@Override public void doOnCreate(Activity activity, Bundle onSavedInstanceState) { activity.setContentView(R.layout.apptentive_message_center); viewActivity = activity;/*from ww w . j a v a 2s .c o m*/ listViewSavedTopIndex = (onSavedInstanceState == null) ? -1 : onSavedInstanceState.getInt(LIST_TOP_INDEX); listViewSavedTopOffset = (onSavedInstanceState == null) ? 0 : onSavedInstanceState.getInt(LIST_TOP_OFFSET); composingViewSavedState = (onSavedInstanceState == null) ? null : onSavedInstanceState.getParcelable(COMPOSING_EDITTEXT_STATE); pendingWhoCardName = (onSavedInstanceState == null) ? null : onSavedInstanceState.getParcelable(WHO_CARD_NAME); pendingWhoCardEmail = (onSavedInstanceState == null) ? null : onSavedInstanceState.getParcelable(WHO_CARD_EMAIL); pendingWhoCardAvatarFile = (onSavedInstanceState == null) ? null : onSavedInstanceState.getString(WHO_CARD_AVATAR_FILE); pendingWhoCardMode = (onSavedInstanceState == null) ? 0 : onSavedInstanceState.getInt(WHO_CARD_MODE); String contextualMessageBody = interaction.getContextualMessageBody(); contextualMessage = CompoundMessage.createAutoMessage(null, contextualMessageBody); setup(); // This listener will run when messages are retrieved from the server, and will start a new thread to update the view. MessageManager.addInternalOnMessagesUpdatedListener(this); // Give the MessageCenterView a callback when a message is sent. MessageManager.setAfterSendMessageListener(this); // Needed to prevent the window from being pushed up when a text input area is focused. activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); if (listViewSavedTopIndex == -1) { messageCenterViewHandler.sendEmptyMessageDelayed(MSG_SCROLL_TO_BOTTOM, DEFAULT_DELAYMILLIS); } }
From source file:com.commonsware.cwac.masterdetail.MasterDetailHelper.java
/** * Initializes the master-detail UI. This should be called * from onCreate() of the activity that is implementing * the master-detail pattern./*w ww . j ava2 s. c om*/ * * @param host * the activity implementing the master-detail * pattern * @param state * the Bundle passed into the activity's * onCreate() method */ @SuppressWarnings("unchecked") public void onCreate(Activity host, Bundle state) { this.host = host; if (state != null) { pagerId = state.getInt(STATE_PAGER_ID, -1); } if (pagerId == -1) { pagerId = generateViewId(); // must have an ID to // work } modelCollectionFragment = (ModelCollectionFragment<T>) getFragmentManager() .findFragmentByTag(getModelFragmentTag()); if (modelCollectionFragment == null) { modelCollectionFragment = new ModelCollectionFragment<T>().modelCollection(buildModelCollection()); getFragmentManager().beginTransaction().add(modelCollectionFragment, getModelFragmentTag()).commit(); } int minDip = getMinimumDipWidthForDualPane(); if (getResources().getConfiguration().screenWidthDp >= minDip || getResources().getConfiguration().screenHeightDp >= minDip) { strategy = new MasterDetailStrategy.DualPane(this, pagerId); } else { strategy = new MasterDetailStrategy.SinglePane(this, pagerId); } pages = buildPagerAdapter(getFragmentManager()); host.setContentView(strategy.getContentView(pages)); lv = (ListView) host.findViewById(android.R.id.list); ListAdapter adapter = buildListAdapter(); adapter.registerDataSetObserver(masterObserver); setListAdapter(adapter); if (offerActionMode()) { getListView().setOnItemLongClickListener(this); } getListView().setChoiceMode(getDefaultChoiceMode()); if (state != null) { if (state.getBoolean(STATE_MC, false)) { getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); getListView().setMultiChoiceModeListener(this); } else { int position = state.getInt(STATE_CHECKED, -1); if (position > -1 && state.getBoolean(STATE_SHOW_DETAIL, false)) { showDetail(position); } else { strategy.clearDetail(); } } } }
From source file:org.navitproject.navit.NavitGraphics.java
public NavitGraphics(final Activity activity, NavitGraphics parent, int x, int y, int w, int h, int wraparound, int use_camera) { if (parent == null) { this.activity = (Navit) activity; view = new NavitView(activity); //activity.registerForContextMenu(view); view.setClickable(false);//from w w w .j a v a2s .c o m view.setFocusable(true); view.setFocusableInTouchMode(true); view.setKeepScreenOn(true); relativelayout = new RelativeLayout(activity); if (use_camera != 0) { SetCamera(use_camera); } relativelayout.addView(view); /* The navigational and status bar tinting code is meaningful only on API19+ */ if (Build.VERSION.SDK_INT >= 19) { frameLayout = new FrameLayout(activity); frameLayout.addView(relativelayout); navigationTintView = new SystemBarTintView(activity); statusTintView = new SystemBarTintView(activity); frameLayout.addView(navigationTintView); frameLayout.addView(statusTintView); activity.setContentView(frameLayout); } else { activity.setContentView(relativelayout); } view.requestFocus(); } else { draw_bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); bitmap_w = w; bitmap_h = h; pos_x = x; pos_y = y; pos_wraparound = wraparound; draw_canvas = new Canvas(draw_bitmap); parent.overlays.add(this); } parent_graphics = parent; }
From source file:org.cryptsecure.Utility.java
/** * Sets the content view with custom title. This is necessary for a holo * layout where a custom title bar is normally not permitted. * //from ww w . ja v a 2 s. co m * @param activity * the activity * @param resIdMainLayout * the res id main layout * @param resIdTitle * the res id title * @return the linear layout */ public static LinearLayout setContentViewWithCustomTitle(Activity activity, int resIdMainLayout, int resIdTitle) { Context context = activity.getApplicationContext(); // Inflate the given layouts LayoutInflater inflaterInfo = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View titleView = (View) inflaterInfo.inflate(resIdTitle, null); View mainView = (View) inflaterInfo.inflate(resIdMainLayout, null); // Own custom title bar // // ATTENTION: // ADD THIS TO THEME <item name="android:windowNoTitle">true</item> activity.requestWindowFeature(Window.FEATURE_NO_TITLE); // We can ONLY disable the original title bar because you cannot combine // HOLO theme with a CUSTOM title bar :( // So we make our own title bar instead! // ALSO REMOVE TITLEBAR FROM APPLICATION AT STARTUP: // ADD TO MANIFEST // android:theme="@android:style/Theme.NoTitleBar" // THE FOLLOWING IS NOT WORKING WITH HOLO // requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); // setContentView(R.layout.activity_main); // getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, // R.layout.title_main); // Create title layout LinearLayout.LayoutParams lpTitle = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); LinearLayout titleLayout = new LinearLayout(context); titleLayout.setOrientation(LinearLayout.VERTICAL); titleLayout.addView(titleView); titleLayout.setLayoutParams(lpTitle); // Create main layout LinearLayout.LayoutParams lpMain = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); LinearLayout mainLayout = new LinearLayout(context); mainLayout.setOrientation(LinearLayout.VERTICAL); mainLayout.addView(mainView); mainLayout.setLayoutParams(lpMain); // Create root outer layout LinearLayout outerLayout = new LinearLayout(context); outerLayout.setOrientation(LinearLayout.VERTICAL); outerLayout.addView(titleLayout); outerLayout.addView(mainLayout); // outerLayout.setBackgroundColor(Color.rgb(255, 0, 0)); // mainLayout.setBackgroundColor(Color.rgb(0, 255, 0)); // titleLayout.setBackgroundColor(Color.rgb(0, 0, 255)); // lpSectionInnerLeft.setMargins(20, 5, 0, 15); // LinearLayout.LayoutParams lpSectionInnerRight = new // LinearLayout.LayoutParams( // 90, LinearLayout.LayoutParams.WRAP_CONTENT, 0f); // lpSectionInnerRight.setMargins(0, 5, 15, 15); // After setting NO TITLE .. apply the layout activity.setContentView(outerLayout); return mainLayout; }