Java Code Examples for android.widget.ToggleButton#setOnClickListener()

The following examples show how to use android.widget.ToggleButton#setOnClickListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LightSwitchActivity.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void onCreate(final Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.main);

	final ImageView image = (ImageView) findViewById(R.id.image);
	final ToggleButton button = (ToggleButton) findViewById(R.id.button);
	button.setOnClickListener(new OnClickListener() {
		@Override
		public void onClick(final View v) {
			TransitionDrawable drawable = (TransitionDrawable) image
					.getDrawable();
			if (button.isChecked()) {
				drawable.startTransition(1000);
			} else {
				drawable.reverseTransition(1000);
			}
		}
	});
}
 
Example 2
Source File: LightSwitchActivity.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void onCreate(final Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.main);
	if (BuildConfig.DEBUG) {
		Log.i("CATEGORY", "AHHHHH!!!");
	}
	
	final ImageView image = (ImageView) findViewById(R.id.image);
	final ToggleButton button = (ToggleButton) findViewById(R.id.button);
	button.setOnClickListener(new OnClickListener() {
		@Override
		public void onClick(final View v) {
			TransitionDrawable drawable = (TransitionDrawable) image
					.getDrawable();
			if (button.isChecked()) {
				drawable.startTransition(1000);
			} else {
				drawable.reverseTransition(1000);
			}
		}
	});
}
 
Example 3
Source File: MainActivity.java    From android-apps with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_main);
			
	tb1 = (ToggleButton) findViewById(R.id.number_one);
	tb2 = (ToggleButton) findViewById(R.id.number_two);
	tb3 = (ToggleButton) findViewById(R.id.number_three);
	tb4 = (ToggleButton) findViewById(R.id.number_four);
	tb5 = (ToggleButton) findViewById(R.id.number_five);
	
	tb1.setOnClickListener(this);
	tb2.setOnClickListener(this);
	tb3.setOnClickListener(this);
	tb4.setOnClickListener(this);
	tb5.setOnClickListener(this);
	
}
 
Example 4
Source File: ThreadReplyActivity.java    From BigApp_Discuz_Android with Apache License 2.0 6 votes vote down vote up
@Override
public boolean initWidget() {
    ActionBarUtils.setHomeActionBar(this, R.drawable.ic_back);


    gridView = (GridView) findViewById(R.id.gridView);
    et = (EmoticonsEditText) findViewById(R.id.et);
    et1 = (EmoticonsEditText) findViewById(R.id.et1);
    tb = (ToggleButton) findViewById(R.id.tb);
    spinner = (BetterSpinner) findViewById(R.id.spinner);
    chooseThread = (TextView) findViewById(R.id.chooseThread);

    tb.setOnClickListener(this);

    et1.setVisibility(View.GONE);

    if (!FileUtils.isExists(SmileyUtils.getSmileyZipFilePath(this))) {
        tb.setVisibility(View.GONE);
    }

    return super.initWidget();
}
 
Example 5
Source File: WSActivity.java    From AndroidWebServ with Apache License 2.0 6 votes vote down vote up
private void initViews(Bundle state) {
    toggleBtn = (ToggleButton) findViewById(R.id.toggleBtn);
    toggleBtn.setOnClickListener(this);
    urlText = (TextView) findViewById(R.id.urlText);
    qrCodeView = (ImageView) findViewById(R.id.qrCodeView);
    contentLayout = (LinearLayout) findViewById(R.id.contentLayout);

    if (state != null) {
        ipAddr = state.getString("ipAddr");
        needResumeServer = state.getBoolean("needResumeServer", false);
        boolean isRunning = state.getBoolean("isRunning", false);
        if (isRunning) {
            toggleBtn.setChecked(true);
            setUrlText(ipAddr);
            doBindService();
        }
    }
}
 
Example 6
Source File: MainActivity.java    From android-apps with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_main);
			
	tb1 = (ToggleButton) findViewById(R.id.number_one);
	tb2 = (ToggleButton) findViewById(R.id.number_two);
	tb3 = (ToggleButton) findViewById(R.id.number_three);
	tb4 = (ToggleButton) findViewById(R.id.number_four);
	tb5 = (ToggleButton) findViewById(R.id.number_five);
	
	tb1.setOnClickListener(this);
	tb2.setOnClickListener(this);
	tb3.setOnClickListener(this);
	tb4.setOnClickListener(this);
	tb5.setOnClickListener(this);
	
}
 
Example 7
Source File: LightSwitchFragment.java    From arcusandroid with Apache License 2.0 5 votes vote down vote up
@Override
public void doStatusSection() {
    View energyView = statusView.findViewById(R.id.light_switch_status_energy);
    toggleButton = (ToggleButton) statusView.findViewById(R.id.light_switch_toggle_button);

    TextView powerUsageTopText = (TextView) energyView.findViewById(R.id.top_status_text);
    powerUsageBottomText = (TextView) energyView.findViewById(R.id.bottom_status_text);
    powerUsageElement = (LinearLayout) energyView.findViewById(R.id.light_switch_status_energy);
    if(hideEnergy) {
        powerUsageElement.setVisibility(View.INVISIBLE);
    } else {
        powerUsageElement.setVisibility(View.VISIBLE);
    }

    powerUsageTopText.setText(getString(R.string.energy_usage_text));
    updatePowerUsage(powerUsageBottomText);

    toggleButton.setChecked(shouldGlow());
    updateImageGlow();

    toggleButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            toggleButton.setEnabled(false);
            updateCheckedState(toggleButton.isChecked());
        }
    });
}
 
Example 8
Source File: BinarySwitchCardItemView.java    From arcusandroid with Apache License 2.0 5 votes vote down vote up
public void build(@NonNull BinarySwitchCard card) {
    super.build(card);
    clickListener = card.getClickListener();

    TextView title = (TextView)this.findViewById(R.id.title);
    title.setText(card.getTitle());
    if(card.getTitleColor() != -1) {
        title.setTextColor(card.getTitleColor());
    }

    TextView description = (TextView)this.findViewById(R.id.description);
    description.setText(card.getDescription());
    if(card.getTitleColor() != -1) {
        description.setTextColor(card.getTitleColor());
    }

    CardView cardView = (CardView) findViewById(R.id.cardView);
    if (cardView != null) {
        cardView.setCardBackgroundColor(Color.TRANSPARENT);
    }

    if (card.isDividerShown()) {
        showDivider();
    }

    ToggleButton button = (ToggleButton) this.findViewById(R.id.toggle);
    if (button != null) {
        button.setOnClickListener(this);
        button.setChecked(card.getToggleChecked());
    }
}
 
Example 9
Source File: Animate_CameraActivity.java    From TraceByAmap with MIT License 5 votes vote down vote up
/**
 * 初始化AMap对象
 */
private void init() {
	if (aMap == null) {
		aMap = mapView.getMap();
	}
	Button stopAnimation = (Button) findViewById(R.id.stop_animation);
	stopAnimation.setOnClickListener(this);
	
	ToggleButton animate = (ToggleButton) findViewById(R.id.animate);
	animate.setOnClickListener(this);
	
	Button Lujiazui = (Button) findViewById(R.id.Lujiazui);
	Lujiazui.setOnClickListener(this);
	
	Button Zhongguancun = (Button) findViewById(R.id.Zhongguancun);
	Zhongguancun.setOnClickListener(this);
	
	Button scrollLeft = (Button) findViewById(R.id.scroll_left);
	scrollLeft.setOnClickListener(this);
	
	Button scrollRight = (Button) findViewById(R.id.scroll_right);
	scrollRight.setOnClickListener(this);
	
	Button scrollUp = (Button) findViewById(R.id.scroll_up);
	scrollUp.setOnClickListener(this);
	
	Button scrollDown = (Button) findViewById(R.id.scroll_down);
	scrollDown.setOnClickListener(this);
}
 
Example 10
Source File: MainActivity.java    From RecordPath3D with Apache License 2.0 5 votes vote down vote up
/**
 * 初始化AMap对象
 */
private void init() {
	if (mAMap == null) {
		mAMap = mMapView.getMap();
		setUpMap();
	}
	btn = (ToggleButton) findViewById(R.id.locationbtn);
	btn.setOnClickListener(new OnClickListener() {
		@Override
		public void onClick(View v) {
			if (btn.isChecked()) {
				Log.i("MY", "isChecked");

				mAMap.clear(true);
				if (record != null) {
					record = null;
				}
				record = new PathRecord();
				mStartTime = System.currentTimeMillis();
				record.setDate(getcueDate(mStartTime));
			} else {
				mEndTime = System.currentTimeMillis();
				saveRecord(record.getPathline(), record.getDate());
			}
		}
	});

}
 
Example 11
Source File: MainActivity.java    From AndroidDemoProjects with Apache License 2.0 5 votes vote down vote up
private void initFlashlightButton() {
	ToggleButton button = (ToggleButton) findViewById( R.id.button_flashlight );
	button.setOnClickListener( new View.OnClickListener() {
		@Override
		public void onClick(View view) {
			if( getPackageManager().hasSystemFeature( PackageManager.FEATURE_CAMERA_FLASH ) )
			{
				if( mFlashlightOn )
					deactivateFlashlight();
				else
					activateFlashlight();
			}
		}
	});
}
 
Example 12
Source File: AddHotAddressActivity.java    From bither-android with Apache License 2.0 5 votes vote down vote up
private void initView() {
    tbtnHDAccount = (ToggleButton) findViewById(R.id.tbtn_hd_account);
    tbtnOther = (ToggleButton) findViewById(R.id.tbtn_other);
    pager = (ViewPager) findViewById(R.id.pager);
    ibtnCancel = (ImageButton) findViewById(R.id.ibtn_cancel);
    tbtnHDAccount.setOnClickListener(new IndicatorClick(0));
    tbtnOther.setOnClickListener(new IndicatorClick(1));
    ibtnCancel.setOnClickListener(cancelClick);
    pager.setAdapter(adapter);
    pager.setOnPageChangeListener(pageChange);
    pager.setCurrentItem(0);
    tbtnHDAccount.setChecked(true);
}
 
Example 13
Source File: MainActivity.java    From Android-FPVDemo with MIT License 5 votes vote down vote up
private void initUI() {
    // init mVideoSurface
    mVideoSurface = (TextureView)findViewById(R.id.video_previewer_surface);

    recordingTime = (TextView) findViewById(R.id.timer);
    mCaptureBtn = (Button) findViewById(R.id.btn_capture);
    mRecordBtn = (ToggleButton) findViewById(R.id.btn_record);
    mShootPhotoModeBtn = (Button) findViewById(R.id.btn_shoot_photo_mode);
    mRecordVideoModeBtn = (Button) findViewById(R.id.btn_record_video_mode);

    if (null != mVideoSurface) {
        mVideoSurface.setSurfaceTextureListener(this);
    }

    mCaptureBtn.setOnClickListener(this);
    mRecordBtn.setOnClickListener(this);
    mShootPhotoModeBtn.setOnClickListener(this);
    mRecordVideoModeBtn.setOnClickListener(this);

    recordingTime.setVisibility(View.INVISIBLE);

    mRecordBtn.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                startRecord();
            } else {
                stopRecord();
            }
        }
    });
}
 
Example 14
Source File: RecipeActivity.java    From search-samples with Apache License 2.0 4 votes vote down vote up
private void showRecipe(Uri recipeUri) {
    Log.d("Recipe Uri", recipeUri.toString());

    String[] projection = {RecipeTable.ID, RecipeTable.TITLE,
            RecipeTable.DESCRIPTION, RecipeTable.PHOTO,
            RecipeTable.PREP_TIME};
    Cursor cursor = getContentResolver().query(recipeUri, projection, null, null, null);
    if (cursor != null && cursor.moveToFirst()) {

        mRecipe = Recipe.fromCursor(cursor);

        Uri ingredientsUri = RecipeContentProvider.CONTENT_URI.buildUpon().appendPath
                ("ingredients").appendPath(mRecipe.getId()).build();
        Cursor ingredientsCursor = getContentResolver().query(ingredientsUri, projection,
                null, null, null);
        if (ingredientsCursor != null && ingredientsCursor.moveToFirst()) {
            do {
                Recipe.Ingredient ingredient = new Recipe.Ingredient();
                ingredient.setAmount(ingredientsCursor.getString(0));
                ingredient.setDescription(ingredientsCursor.getString(1));
                mRecipe.addIngredient(ingredient);
                ingredientsCursor.moveToNext();
            } while (!ingredientsCursor.isAfterLast());
            ingredientsCursor.close();
        }

        Uri instructionsUri = RecipeContentProvider.CONTENT_URI.buildUpon().appendPath
                ("instructions").appendPath(mRecipe.getId()).build();
        Cursor instructionsCursor = getContentResolver().query(instructionsUri, projection,
                null, null, null);
        if (instructionsCursor != null && instructionsCursor.moveToFirst()) {
            do {
                Recipe.Step step = new Recipe.Step();
                step.setDescription(instructionsCursor.getString(1));
                step.setPhoto(instructionsCursor.getString(2));
                mRecipe.addStep(step);
                instructionsCursor.moveToNext();
            } while (!instructionsCursor.isAfterLast());
            instructionsCursor.close();
        }

        Uri noteUri = RecipeContentProvider.CONTENT_URI.buildUpon().appendPath("notes")
                .appendPath(mRecipe.getId()).build();
        Cursor noteCursor = getContentResolver().query(noteUri, projection, null, null, null);
        if (noteCursor != null && noteCursor.moveToFirst()) {
            Note note = Note.fromCursor(noteCursor);
            mRecipe.setNote(note);
            noteCursor.close();
        }

        // always close the cursor
        cursor.close();
    } else {
        Toast toast = Toast.makeText(getApplicationContext(),
                "No match for deep link " + recipeUri.toString(),
                Toast.LENGTH_SHORT);
        toast.show();
    }

    if (mRecipe != null) {
        // Create the adapter that will return a fragment for each of the steps of the recipe.
        mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager());

        // Set up the ViewPager with the sections adapter.
        mViewPager = (ViewPager) findViewById(R.id.pager);
        mViewPager.setAdapter(mSectionsPagerAdapter);

        // Set the recipe title
        TextView recipeTitle = (TextView) findViewById(R.id.recipeTitle);
        recipeTitle.setText(mRecipe.getTitle());

        // Set the recipe prep time
        TextView recipeTime = (TextView) findViewById(R.id.recipeTime);
        recipeTime.setText("  " + mRecipe.getPrepTime());

        //Set the note button toggle
        ToggleButton addNoteToggle = (ToggleButton) findViewById(R.id.addNoteToggle);
        addNoteToggle.setChecked(mRecipe.getNote() != null);
        addNoteToggle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mRecipe.getNote() != null) {
                    displayNoteDialog(getString(R.string.dialog_update_note), getString(R
                            .string.dialog_delete_note));
                } else {
                    displayNoteDialog(getString(R.string.dialog_add_note), getString(R.string
                            .dialog_cancel_note));
                }
            }
        });
    }
}
 
Example 15
Source File: LogsFragment.java    From callmeter with GNU General Public License v3.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.logs, container, false);
    tbCall = (ToggleButton) v.findViewById(R.id.calls);
    tbCall.setOnClickListener(this);
    tbSMS = (ToggleButton) v.findViewById(R.id.sms);
    tbSMS.setOnClickListener(this);
    tbMMS = (ToggleButton) v.findViewById(R.id.mms);
    tbMMS.setOnClickListener(this);
    tbData = (ToggleButton) v.findViewById(R.id.data);
    tbData.setOnClickListener(this);
    tbIn = (ToggleButton) v.findViewById(R.id.in);
    tbIn.setOnClickListener(this);
    tbOut = (ToggleButton) v.findViewById(R.id.out);
    tbOut.setOnClickListener(this);
    tbPlan = (ToggleButton) v.findViewById(R.id.plan);
    tbPlan.setOnClickListener(this);
    final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(this
            .getActivity());
    tbCall.setChecked(p.getBoolean(PREF_CALL, true));
    tbSMS.setChecked(p.getBoolean(PREF_SMS, true));
    tbMMS.setChecked(p.getBoolean(PREF_MMS, true));
    tbData.setChecked(p.getBoolean(PREF_DATA, true));
    tbIn.setChecked(p.getBoolean(PREF_IN, true));
    tbOut.setChecked(p.getBoolean(PREF_OUT, true));

    String[] directions = getResources().getStringArray(R.array.direction_calls);
    tbIn.setText(directions[DataProvider.DIRECTION_IN]);
    tbIn.setTextOn(directions[DataProvider.DIRECTION_IN]);
    tbIn.setTextOff(directions[DataProvider.DIRECTION_IN]);
    tbOut.setText(directions[DataProvider.DIRECTION_OUT]);
    tbOut.setTextOn(directions[DataProvider.DIRECTION_OUT]);
    tbOut.setTextOff(directions[DataProvider.DIRECTION_OUT]);

    if (planId >= 0L) {
        setPlanId(planId);
    }

    return v;
}
 
Example 16
Source File: MainActivity.java    From arcgis-runtime-samples-android with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);

  // create scene view from layout
  mSceneView = findViewById(R.id.sceneView);
  // create a scene and add a basemap to it
  ArcGISScene scene = new ArcGISScene();
  scene.setBasemap(Basemap.createImagery());
  mSceneView.setScene(scene);

  // add base surface for elevation data
  ArcGISTiledElevationSource elevationSource = new ArcGISTiledElevationSource(
      getString(R.string.elevation_image_service));
  scene.getBaseSurface().getElevationSources().add(elevationSource);

  // add a camera and initial camera position
  Camera camera = new Camera(53.05, -4.01, 1115, 299, 88, 0);
  mSceneView.setViewpointCamera(camera);

  // create point for graphic location
  Point point = new Point(-4.04, 53.06, 1000, camera.getLocation().getSpatialReference());

  // create a red triangle symbol
  SimpleMarkerSymbol triangleSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.TRIANGLE, Color.RED, 10);

  // create the draped flat overlay
  GraphicsOverlay drapedFlatOverlay = new GraphicsOverlay();
  drapedFlatOverlay.getSceneProperties().setSurfacePlacement(SurfacePlacement.DRAPED_FLAT);
  drapedFlatOverlay.getGraphics().add(new Graphic(point, triangleSymbol));
  // create a text symbol for elevation mode
  TextSymbol drapedFlatText = new TextSymbol(10, "DRAPED FLAT", Color.WHITE, HorizontalAlignment.LEFT,
      VerticalAlignment.MIDDLE);
  drapedFlatText.setOffsetY(20);
  drapedFlatOverlay.getGraphics().add(new Graphic(point, drapedFlatText));
  mSceneView.getGraphicsOverlays().add(drapedFlatOverlay);

  // create the draped billboarded overlay
  GraphicsOverlay drapedBillboardedOverlay = new GraphicsOverlay();
  drapedBillboardedOverlay.getSceneProperties().setSurfacePlacement(SurfacePlacement.DRAPED_BILLBOARDED);
  drapedBillboardedOverlay.getGraphics().add(new Graphic(point, triangleSymbol));
  // create a text symbol for elevation mode
  TextSymbol drapedBillboardedText = new TextSymbol(10, "DRAPED BILLBOARDED", Color.WHITE, HorizontalAlignment.LEFT,
      VerticalAlignment.MIDDLE);
  drapedBillboardedText.setOffsetY(20);
  drapedBillboardedOverlay.getGraphics().add(new Graphic(point, drapedBillboardedText));
  mSceneView.getGraphicsOverlays().add(drapedBillboardedOverlay);
  drapedBillboardedOverlay.setVisible(false);

  // create the relative overlay
  GraphicsOverlay relativeOverlay = new GraphicsOverlay();
  relativeOverlay.getSceneProperties().setSurfacePlacement(SurfacePlacement.RELATIVE);
  relativeOverlay.getGraphics().add(new Graphic(point, triangleSymbol));
  // create a text symbol for elevation mode
  TextSymbol relativeText = new TextSymbol(10, "RELATIVE", Color.WHITE, HorizontalAlignment.LEFT,
      VerticalAlignment.MIDDLE);
  relativeText.setOffsetY(20);
  relativeOverlay.getGraphics().add(new Graphic(point, relativeText));
  mSceneView.getGraphicsOverlays().add(relativeOverlay);

  // create the absolute overlay
  GraphicsOverlay absoluteOverlay = new GraphicsOverlay();
  absoluteOverlay.getSceneProperties().setSurfacePlacement(SurfacePlacement.ABSOLUTE);
  absoluteOverlay.getGraphics().add(new Graphic(point, triangleSymbol));
  // create a text symbol for elevation mode
  TextSymbol absoluteText = new TextSymbol(10, "ABSOLUTE", Color.WHITE, HorizontalAlignment.LEFT,
      VerticalAlignment.MIDDLE);
  absoluteText.setOffsetY(20);
  absoluteOverlay.getGraphics().add(new Graphic(point, absoluteText));
  mSceneView.getGraphicsOverlays().add(absoluteOverlay);

  // toggle visibility of the draped and billboarded graphics overlays
  ToggleButton drapedToggle = findViewById(R.id.drapedToggle);
  drapedToggle.setOnClickListener(v -> {
    drapedBillboardedOverlay.setVisible(drapedToggle.isChecked());
    drapedFlatOverlay.setVisible(!drapedToggle.isChecked());
  });
}
 
Example 17
Source File: PostFeedActivity.java    From umeng_community_android with MIT License 4 votes vote down vote up
/**
 * 初始化相关View
 */
protected void initViews() {
    // 发送和回退按钮
    findViewById(ResFinder.getId("umeng_comm_post_ok_btn")).setOnClickListener(this);
    findViewById(ResFinder.getId("umeng_comm_post_back_btn")).setOnClickListener(this);

    mLocProgressBar = (ProgressBar) findViewById(ResFinder.getId(
            "umeng_comm_post_loc_progressbar"));

    mLocIcon = (ImageView) findViewById(ResFinder.getId("umeng_comm_post_loc_icon"));
    mLocIcon.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            initLocationLayout();
        }
    });
    mLocationTv = (TextView) findViewById(ResFinder.getId("umeng_comm_location_text"));
    mLocationLayout = findViewById(
            ResFinder.getId("umeng_community_loc_layout"));

    initEditView();
    // 以下四个按钮分别是选择话题、添加图片、选择位置、@好友
    findViewById(ResFinder.getId("umeng_comm_take_photo_btn")).setOnClickListener(this);
    findViewById(ResFinder.getId("umeng_comm_select_location_btn")).setOnClickListener(
            this);
    findViewById(ResFinder.getId("umeng_comm_at_friend_btn")).setOnClickListener(this);

    mPhotoButton = (ImageButton) findViewById(ResFinder
            .getId("umeng_comm_add_image_btn"));
    mPhotoButton.setOnClickListener(this);
    mTopicButton = (ToggleButton) findViewById(ResFinder.getId(
            "umeng_comm_pick_topic_btn"));
    mTopicButton.setOnClickListener(this);

    mFragmentLatout = (FrameLayout)
            findViewById(ResFinder.getId("umeng_comm_select_layout"));
    mGridView = (GridView) findViewById(ResFinder.getId("umeng_comm_prev_images_gv"));
    initSelectedImageAdapter();
    mTopicTipView = (TopicTipView) findViewById(ResFinder.getId("umeng_comm_topic_tip"));
    if (CommConfig.getConfig().loginedUser.gender == Gender.FEMALE) {// 根据性别做不同的提示
        mTopicTipView.setText(ResFinder.getString("umeng_comm_topic_tip_female"));
    }
    if (!isForwardFeed) {
        startAnimationForTopicTipView();
    }
}
 
Example 18
Source File: RecipeActivity.java    From app-indexing with Apache License 2.0 4 votes vote down vote up
private void showRecipe(Uri recipeUri) {
    Log.d("Recipe Uri", recipeUri.toString());

    String[] projection = {RecipeTable.ID, RecipeTable.TITLE,
            RecipeTable.DESCRIPTION, RecipeTable.PHOTO,
            RecipeTable.PREP_TIME};
    Cursor cursor = getContentResolver().query(recipeUri, projection, null, null, null);
    if (cursor != null && cursor.moveToFirst()) {

        mRecipe = Recipe.fromCursor(cursor);

        Uri ingredientsUri = RecipeContentProvider.CONTENT_URI.buildUpon().appendPath
                ("ingredients").appendPath(mRecipe.getId()).build();
        Cursor ingredientsCursor = getContentResolver().query(ingredientsUri, projection,
                null, null, null);
        if (ingredientsCursor != null && ingredientsCursor.moveToFirst()) {
            do {
                Recipe.Ingredient ingredient = new Recipe.Ingredient();
                ingredient.setAmount(ingredientsCursor.getString(0));
                ingredient.setDescription(ingredientsCursor.getString(1));
                mRecipe.addIngredient(ingredient);
                ingredientsCursor.moveToNext();
            } while (!ingredientsCursor.isAfterLast());
            ingredientsCursor.close();
        }

        Uri instructionsUri = RecipeContentProvider.CONTENT_URI.buildUpon().appendPath
                ("instructions").appendPath(mRecipe.getId()).build();
        Cursor instructionsCursor = getContentResolver().query(instructionsUri, projection,
                null, null, null);
        if (instructionsCursor != null && instructionsCursor.moveToFirst()) {
            do {
                Recipe.Step step = new Recipe.Step();
                step.setDescription(instructionsCursor.getString(1));
                step.setPhoto(instructionsCursor.getString(2));
                mRecipe.addStep(step);
                instructionsCursor.moveToNext();
            } while (!instructionsCursor.isAfterLast());
            instructionsCursor.close();
        }

        Uri noteUri = RecipeContentProvider.CONTENT_URI.buildUpon().appendPath("notes")
                .appendPath(mRecipe.getId()).build();
        Cursor noteCursor = getContentResolver().query(noteUri, projection, null, null, null);
        if (noteCursor != null && noteCursor.moveToFirst()) {
            Note note = Note.fromCursor(noteCursor);
            mRecipe.setNote(note);
            noteCursor.close();
        }

        // always close the cursor
        cursor.close();
    } else {
        Toast toast = Toast.makeText(getApplicationContext(),
                "No match for deep link " + recipeUri.toString(),
                Toast.LENGTH_SHORT);
        toast.show();
    }

    if (mRecipe != null) {
        // Create the adapter that will return a fragment for each of the steps of the recipe.
        mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager());

        // Set up the ViewPager with the sections adapter.
        mViewPager = (ViewPager) findViewById(R.id.pager);
        mViewPager.setAdapter(mSectionsPagerAdapter);

        // Set the recipe title
        TextView recipeTitle = (TextView) findViewById(R.id.recipeTitle);
        recipeTitle.setText(mRecipe.getTitle());

        // Set the recipe prep time
        TextView recipeTime = (TextView) findViewById(R.id.recipeTime);
        recipeTime.setText("  " + mRecipe.getPrepTime());

        //Set the note button toggle
        ToggleButton addNoteToggle = (ToggleButton) findViewById(R.id.addNoteToggle);
        addNoteToggle.setChecked(mRecipe.getNote() != null);
        addNoteToggle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mRecipe.getNote() != null) {
                    displayNoteDialog(getString(R.string.dialog_update_note), getString(R
                            .string.dialog_delete_note));
                } else {
                    displayNoteDialog(getString(R.string.dialog_add_note), getString(R.string
                            .dialog_cancel_note));
                }
            }
        });
    }
}
 
Example 19
Source File: RecipeActivity.java    From app-indexing with Apache License 2.0 4 votes vote down vote up
private void showRecipe(Uri recipeUri) {
    Log.d("Recipe Uri", recipeUri.toString());

    String[] projection = {RecipeTable.ID, RecipeTable.TITLE,
            RecipeTable.DESCRIPTION, RecipeTable.PHOTO,
            RecipeTable.PREP_TIME};
    Cursor cursor = getContentResolver().query(recipeUri, projection, null, null, null);
    if (cursor != null && cursor.moveToFirst()) {

        mRecipe = Recipe.fromCursor(cursor);

        Uri ingredientsUri = RecipeContentProvider.CONTENT_URI.buildUpon().appendPath
                ("ingredients").appendPath(mRecipe.getId()).build();
        Cursor ingredientsCursor = getContentResolver().query(ingredientsUri, projection,
                null, null, null);
        if (ingredientsCursor != null && ingredientsCursor.moveToFirst()) {
            do {
                Recipe.Ingredient ingredient = new Recipe.Ingredient();
                ingredient.setAmount(ingredientsCursor.getString(0));
                ingredient.setDescription(ingredientsCursor.getString(1));
                mRecipe.addIngredient(ingredient);
                ingredientsCursor.moveToNext();
            } while (!ingredientsCursor.isAfterLast());
            ingredientsCursor.close();
        }

        Uri instructionsUri = RecipeContentProvider.CONTENT_URI.buildUpon().appendPath
                ("instructions").appendPath(mRecipe.getId()).build();
        Cursor instructionsCursor = getContentResolver().query(instructionsUri, projection,
                null, null, null);
        if (instructionsCursor != null && instructionsCursor.moveToFirst()) {
            do {
                Recipe.Step step = new Recipe.Step();
                step.setDescription(instructionsCursor.getString(1));
                step.setPhoto(instructionsCursor.getString(2));
                mRecipe.addStep(step);
                instructionsCursor.moveToNext();
            } while (!instructionsCursor.isAfterLast());
            instructionsCursor.close();
        }

        Uri noteUri = RecipeContentProvider.CONTENT_URI.buildUpon().appendPath("notes")
                .appendPath(mRecipe.getId()).build();
        Cursor noteCursor = getContentResolver().query(noteUri, projection, null, null, null);
        if (noteCursor != null && noteCursor.moveToFirst()) {
            Note note = Note.fromCursor(noteCursor);
            mRecipe.setNote(note);
            noteCursor.close();
        }

        // always close the cursor
        cursor.close();
    } else {
        Toast toast = Toast.makeText(getApplicationContext(),
                "No match for deep link " + recipeUri.toString(),
                Toast.LENGTH_SHORT);
        toast.show();
    }

    if (mRecipe != null) {
        // Create the adapter that will return a fragment for each of the steps of the recipe.
        mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager());

        // Set up the ViewPager with the sections adapter.
        mViewPager = (ViewPager) findViewById(R.id.pager);
        mViewPager.setAdapter(mSectionsPagerAdapter);

        // Set the recipe title
        TextView recipeTitle = (TextView) findViewById(R.id.recipeTitle);
        recipeTitle.setText(mRecipe.getTitle());

        // Set the recipe prep time
        TextView recipeTime = (TextView) findViewById(R.id.recipeTime);
        recipeTime.setText("  " + mRecipe.getPrepTime());

        //Set the note button toggle
        ToggleButton addNoteToggle = (ToggleButton) findViewById(R.id.addNoteToggle);
        addNoteToggle.setChecked(mRecipe.getNote() != null);
        addNoteToggle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mRecipe.getNote() != null) {
                    displayNoteDialog(getString(R.string.dialog_update_note), getString(R
                            .string.dialog_delete_note));
                } else {
                    displayNoteDialog(getString(R.string.dialog_add_note), getString(R.string
                            .dialog_cancel_note));
                }
            }
        });
    }
}
 
Example 20
Source File: RecipeActivity.java    From search-samples with Apache License 2.0 4 votes vote down vote up
private void showRecipe(Uri recipeUri) {
    Log.d("Recipe Uri", recipeUri.toString());

    String[] projection = {RecipeTable.ID, RecipeTable.TITLE,
            RecipeTable.DESCRIPTION, RecipeTable.PHOTO,
            RecipeTable.PREP_TIME};
    Cursor cursor = getContentResolver().query(recipeUri, projection, null, null, null);
    if (cursor != null && cursor.moveToFirst()) {

        mRecipe = Recipe.fromCursor(cursor);

        Uri ingredientsUri = RecipeContentProvider.CONTENT_URI.buildUpon().appendPath
                ("ingredients").appendPath(mRecipe.getId()).build();
        Cursor ingredientsCursor = getContentResolver().query(ingredientsUri, projection,
                null, null, null);
        if (ingredientsCursor != null && ingredientsCursor.moveToFirst()) {
            do {
                Recipe.Ingredient ingredient = new Recipe.Ingredient();
                ingredient.setAmount(ingredientsCursor.getString(0));
                ingredient.setDescription(ingredientsCursor.getString(1));
                mRecipe.addIngredient(ingredient);
                ingredientsCursor.moveToNext();
            } while (!ingredientsCursor.isAfterLast());
            ingredientsCursor.close();
        }

        Uri instructionsUri = RecipeContentProvider.CONTENT_URI.buildUpon().appendPath
                ("instructions").appendPath(mRecipe.getId()).build();
        Cursor instructionsCursor = getContentResolver().query(instructionsUri, projection,
                null, null, null);
        if (instructionsCursor != null && instructionsCursor.moveToFirst()) {
            do {
                Recipe.Step step = new Recipe.Step();
                step.setDescription(instructionsCursor.getString(1));
                step.setPhoto(instructionsCursor.getString(2));
                mRecipe.addStep(step);
                instructionsCursor.moveToNext();
            } while (!instructionsCursor.isAfterLast());
            instructionsCursor.close();
        }

        Uri noteUri = RecipeContentProvider.CONTENT_URI.buildUpon().appendPath("notes")
                .appendPath(mRecipe.getId()).build();
        Cursor noteCursor = getContentResolver().query(noteUri, projection, null, null, null);
        if (noteCursor != null && noteCursor.moveToFirst()) {
            Note note = Note.fromCursor(noteCursor);
            mRecipe.setNote(note);
            noteCursor.close();
        }

        // always close the cursor
        cursor.close();
    } else {
        Toast toast = Toast.makeText(getApplicationContext(),
                "No match for deep link " + recipeUri.toString(),
                Toast.LENGTH_SHORT);
        toast.show();
    }

    if (mRecipe != null) {
        // Create the adapter that will return a fragment for each of the steps of the recipe.
        mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager());

        // Set up the ViewPager with the sections adapter.
        mViewPager = (ViewPager) findViewById(R.id.pager);
        mViewPager.setAdapter(mSectionsPagerAdapter);

        // Set the recipe title
        TextView recipeTitle = (TextView) findViewById(R.id.recipeTitle);
        recipeTitle.setText(mRecipe.getTitle());

        // Set the recipe prep time
        TextView recipeTime = (TextView) findViewById(R.id.recipeTime);
        recipeTime.setText("  " + mRecipe.getPrepTime());

        //Set the note button toggle
        ToggleButton addNoteToggle = (ToggleButton) findViewById(R.id.addNoteToggle);
        addNoteToggle.setChecked(mRecipe.getNote() != null);
        addNoteToggle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mRecipe.getNote() != null) {
                    displayNoteDialog(getString(R.string.dialog_update_note), getString(R
                            .string.dialog_delete_note));
                } else {
                    displayNoteDialog(getString(R.string.dialog_add_note), getString(R.string
                            .dialog_cancel_note));
                }
            }
        });
    }
}