Java tutorial
/* * ================================================================================================= * Copyright (C) 2014 Martin Albedinsky [Wolf-ITechnologies] * ================================================================================================= * Licensed under the Apache License, Version 2.0 or later (further "License" only). * ------------------------------------------------------------------------------------------------- * You may use this file only in compliance with the License. More details and copy of this License * you may obtain at * * http://www.apache.org/licenses/LICENSE-2.0 * * You can redistribute, modify or publish any part of the code written within this file but as it * is described in the License, the software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES or CONDITIONS OF ANY KIND. * * See the License for the specific language governing permissions and limitations under the License. * ================================================================================================= */ package com.wit.android.support.content.intent; import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.annotation.StringRes; import android.support.v4.app.Fragment; import android.text.TextUtils; import android.util.Log; /** * <h3>Class Overview</h3> * todo: description * * @author Martin Albedinsky */ public class DialerIntent extends BaseIntent<DialerIntent> { /** * Interface =================================================================================== */ /** * Constants =================================================================================== */ /** * Log TAG. */ private static final String TAG = "DialerIntent"; /** * Flag indicating whether the output trough log-cat is enabled or not. */ // private static final boolean LOG_ENABLED = true; /** * Flag indicating whether the debug output trough log-cat is enabled or not. */ // private static final boolean DEBUG_ENABLED = true; /** * Uri scheme for <b>phone dialer</b> targeting intents. * <p> * Constant value: <b>tel:</b> */ public static final String SCHEME = "tel:"; /** * Static members ============================================================================== */ /** * Members ===================================================================================== */ /** * Phone number value for dialer. */ private String mPhoneNumber; /** * Constructors ================================================================================ */ /** * Creates a new instance of DialerIntent for the given <var>activity</var> context. * See {@link com.wit.android.support.content.intent.BaseIntent#BaseIntent(android.app.Activity)} * for additional info. */ public DialerIntent(@NonNull Activity activity) { super(activity); } /** * Creates a new instance of DialerIntent for the given <var>fragment</var> context. * See {@link com.wit.android.support.content.intent.BaseIntent#BaseIntent(android.support.v4.app.Fragment)} * for additional info. */ public DialerIntent(@NonNull Fragment fragment) { super(fragment); } /** * Methods ===================================================================================== */ /** * Public -------------------------------------------------------------------------------------- */ /** */ @Nullable @Override public Intent buildIntent() { if (TextUtils.isEmpty(mPhoneNumber)) { Log.e(TAG, "Can not create an DIALER intent. No phone number specified."); return null; } return new Intent(Intent.ACTION_DIAL, Uri.parse(SCHEME + mPhoneNumber)); } /** * Getters + Setters --------------------------------------------------------------------------- */ /** * Same as {@link #phoneNumber(String)}, where number will be obtain from the current context wrapper * (activity/fragment). * * @param resId Resource id of the desired phone number placed within an application resources. */ public DialerIntent phoneNumber(@StringRes int resId) { return phoneNumber(obtainString(resId)); } /** * Sets the phone number which should be passed to the dialer application. * * @param number The desired phone number. * @return This intent builder to allow methods chaining. */ public DialerIntent phoneNumber(@Nullable String number) { this.mPhoneNumber = number; return this; } /** * Returns the current phone number which should be passed to the dialer application. * * @return Phone number or {@code null} if no number was set yet. */ @Nullable public String getPhoneNumber() { return mPhoneNumber; } /** * Protected ----------------------------------------------------------------------------------- */ /** * Private ------------------------------------------------------------------------------------- */ /** * Inner classes =============================================================================== */ }