Android Open Source - downtown Info Helper






From Project

Back to project page downtown.

License

The source code is released under:

GNU General Public License

If you think the Android project downtown listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.dklisiaris.downtown.helper;
/*  w ww. j  a va  2 s.c  om*/
import org.dklisiaris.downtown.R;

import java.util.ArrayList;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.Build;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

/**
 * Class for building custom dialogs with specific types of information
 * @author meec
 */
public class InfoHelper{
    private Activity mContext;
    private Dialog mDialog;
    private LayoutInflater mInflater;
    private Typeface roboLight;
    private Typeface roboRegular;

    public InfoHelper(Activity context) {
        this.mContext = context;
        // Loading Font Face
        roboLight = Typeface.createFromAsset(mContext.getAssets(), "fonts/Roboto-Light.ttf");
        roboRegular = Typeface.createFromAsset(mContext.getAssets(), "fonts/Roboto-Regular.ttf");
    }

    /**
     * Shows a description dialog.
     * Since v1.7.4 it supports html text.
     * @param desc The text of description to show off
     */
    @SuppressLint("NewApi")
    public void show(String desc) {
        this.mInflater = LayoutInflater.from(mContext);
        final View infoView = mInflater.inflate(R.layout.info_dialog, null);

        TextView dTitle = (TextView)infoView.findViewById(R.id.dialog_title);
        TextView title = (TextView)infoView.findViewById(R.id.title);
        //TextView txt = (TextView)infoView.findViewById(R.id.info_text);
        WebView webDesc = (WebView)infoView.findViewById(R.id.webText);
        Button dialogButton = (Button) infoView.findViewById(R.id.btn_close);

        String header="<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"><title>Lorem Ipsum</title></head><body>";
        String footer="</body></html>";
        //CharSequence descToShow = Html.fromHtml(desc);
        webDesc.setBackgroundColor(0);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            webDesc.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);
        }
        webDesc.setBackgroundColor(Color.TRANSPARENT);
        webDesc.setHorizontalScrollBarEnabled(false);

        webDesc.loadDataWithBaseURL(null, header+desc+footer, "text/html", "utf-8", null);

        Log.d("HTML TEXT",desc);
        dTitle.setText("?????????????");
        title.setText("?????????? ?????????????");
        title.setTypeface(roboLight);
        //txt.setText(descToShow);
        //txt.setTypeface(roboRegular);

        AlertDialog.Builder builder;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            builder = new AlertDialog.Builder(mContext, AlertDialog.THEME_DEVICE_DEFAULT_DARK);
        } else {
            builder = new AlertDialog.Builder(mContext);
        }
        //builder.setTitle("?????????????");
        //builder.setIcon(R.drawable.logobackface);         
        builder.setView(infoView);

        mDialog = builder.create();
        mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);



        dialogButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v)
            {
                mDialog.dismiss();
            }
        });

        mDialog.show();
    }

    /**
     * Shows a telephone dialog in which the users can call the numbers
     * @param tels An arrayList with telephones strings
     * @param fax A string with fax number
     */
    @SuppressLint("NewApi")
    public void show(ArrayList<String> tels, String fax) {
        this.mInflater = LayoutInflater.from(mContext);
        final View infoView = mInflater.inflate(R.layout.tel_dialog, null);

        TextView dTitle = (TextView)infoView.findViewById(R.id.dialog_title);
        TextView titleTel = (TextView)infoView.findViewById(R.id.title_tel);
        TextView titleFax = (TextView)infoView.findViewById(R.id.title_fax);
        final TextView tel1 = (TextView)infoView.findViewById(R.id.tel1);
        final TextView tel2 = (TextView)infoView.findViewById(R.id.tel2);
        final TextView tel3 = (TextView)infoView.findViewById(R.id.tel3);
        final TextView fax1 = (TextView)infoView.findViewById(R.id.fax);
        final RelativeLayout tel1L = (RelativeLayout) infoView.findViewById(R.id.tel1_layout);
        final RelativeLayout tel2L = (RelativeLayout) infoView.findViewById(R.id.tel2_layout);
        final RelativeLayout tel3L = (RelativeLayout) infoView.findViewById(R.id.tel3_layout);
        final RelativeLayout faxL = (RelativeLayout) infoView.findViewById(R.id.fax_layout);
        Button dialogButton = (Button) infoView.findViewById(R.id.btn_close);

        dTitle.setText("????????");

        titleTel.setTypeface(roboLight);
        titleTel.setText("???????? ??? ?????? ????????");

        titleFax.setText("Fax ????????");
        titleFax.setTypeface(roboLight);

        int size=tels.size();
        if(size>0)
            tel1.setText(tels.get(0));
        tel1.setTypeface(roboRegular);
        if(size>1)
            tel2.setText(tels.get(1));
        tel2.setTypeface(roboRegular);
        if(size>2)
            tel3.setText(tels.get(2));
        tel3.setTypeface(roboRegular);
        if(fax!=null && !fax.equals(""))
            fax1.setText(fax);
        fax1.setTypeface(roboRegular);

        AlertDialog.Builder builder;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            builder = new AlertDialog.Builder(mContext, AlertDialog.THEME_DEVICE_DEFAULT_DARK);
        } else {
            builder = new AlertDialog.Builder(mContext);
        }
        //builder.setTitle("?????????????");
        //builder.setIcon(R.drawable.logobackface);         
        builder.setView(infoView);

        mDialog = builder.create();
        mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);


        tel1L.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v)
            {
                if (tel1.getText()==null || tel1.getText().equals("-")){
                    Toast t = Toast.makeText(infoView.getContext(), "?? ????????? ????????", Toast.LENGTH_LONG);
                    t.setGravity(Gravity.TOP|Gravity.CENTER_HORIZONTAL, 0, 0);
                    t.show();
                }
                else{
                    if (!isTelephonyEnabled()){
                        Toast t = Toast.makeText(infoView.getContext(), "? ??????? ??? ??? ???????????? ??????????? ???????.", Toast.LENGTH_LONG);
                        t.setGravity(Gravity.TOP|Gravity.CENTER_HORIZONTAL, 0, 0);
                        t.show();
                    }
                    else{
                        call(tel1.getText().toString());
                    }
                }
            }
        });
        tel2L.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v)
            {
                if (tel2.getText()==null || tel2.getText().equals("-")){
                    Toast t = Toast.makeText(infoView.getContext(), "?? ????????? ????????", Toast.LENGTH_LONG);
                    t.setGravity(Gravity.TOP|Gravity.CENTER_HORIZONTAL, 0, 0);
                    t.show();
                }
                else{
                    if (!isTelephonyEnabled()){
                        Toast t = Toast.makeText(infoView.getContext(), "? ??????? ??? ??? ???????????? ??????????? ???????.", Toast.LENGTH_LONG);
                        t.setGravity(Gravity.TOP|Gravity.CENTER_HORIZONTAL, 0, 0);
                        t.show();
                    }
                    else{
                        call(tel2.getText().toString());
                    }
                }
            }
        });

        tel3L.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v)
            {
                if (tel3.getText()==null || tel3.getText().equals("-")){
                    Toast t = Toast.makeText(infoView.getContext(), "?? ????????? ????????", Toast.LENGTH_LONG);
                    t.setGravity(Gravity.TOP|Gravity.CENTER_HORIZONTAL, 0, 0);
                    t.show();
                }
                else{
                    if (!isTelephonyEnabled()){
                        Toast t = Toast.makeText(infoView.getContext(), "? ??????? ??? ??? ???????????? ??????????? ???????.", Toast.LENGTH_LONG);
                        t.setGravity(Gravity.TOP|Gravity.CENTER_HORIZONTAL, 0, 0);
                        t.show();
                    }
                    else{
                        call(tel3.getText().toString());
                    }
                }
            }
        });

        faxL.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v)
            {
                if (fax1.getText()==null || fax1.getText().equals("-")){
                    Toast t = Toast.makeText(infoView.getContext(), "?? ????????? ????????", Toast.LENGTH_LONG);
                    t.setGravity(Gravity.TOP|Gravity.CENTER_HORIZONTAL, 0, 0);
                    t.show();
                }
                else{
                    if (!isTelephonyEnabled()){
                        Toast t = Toast.makeText(infoView.getContext(), "? ??????? ??? ??? ???????????? ??????????? ???????.", Toast.LENGTH_LONG);
                        t.setGravity(Gravity.TOP|Gravity.CENTER_HORIZONTAL, 0, 0);
                        t.show();
                    }
                    else{
                        call(fax1.getText().toString());
                    }
                }
            }
        });
        dialogButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v)
            {
                mDialog.dismiss();
            }
        });

        mDialog.show();
    }

    public void call(String phone) {
        Intent callIntent = new Intent(Intent.ACTION_DIAL);
        callIntent.setData(Uri.parse("tel:"+phone.replaceAll("\\s","")));
        ((Activity) mContext).startActivity(callIntent);
    }

    private boolean isTelephonyEnabled(){
        TelephonyManager tm = (TelephonyManager)mContext.getSystemService(Activity.TELEPHONY_SERVICE);
        return tm != null && tm.getSimState()==TelephonyManager.SIM_STATE_READY;
    }
}




Java Source Code List

com.google.maps.android.BuildConfig.java
com.google.maps.android.BuildConfig.java
com.google.maps.android.MarkerManager.java
com.google.maps.android.MathUtil.java
com.google.maps.android.PolyUtil.java
com.google.maps.android.SphericalUtil.java
com.google.maps.android.clustering.ClusterItem.java
com.google.maps.android.clustering.ClusterManager.java
com.google.maps.android.clustering.Cluster.java
com.google.maps.android.clustering.algo.Algorithm.java
com.google.maps.android.clustering.algo.GridBasedAlgorithm.java
com.google.maps.android.clustering.algo.NonHierarchicalDistanceBasedAlgorithm.java
com.google.maps.android.clustering.algo.PreCachingAlgorithmDecorator.java
com.google.maps.android.clustering.algo.StaticCluster.java
com.google.maps.android.clustering.view.ClusterRenderer.java
com.google.maps.android.clustering.view.DefaultClusterRenderer.java
com.google.maps.android.geometry.Bounds.java
com.google.maps.android.geometry.Point.java
com.google.maps.android.projection.Point.java
com.google.maps.android.projection.SphericalMercatorProjection.java
com.google.maps.android.quadtree.PointQuadTree.java
com.google.maps.android.ui.BubbleIconFactory.java
com.google.maps.android.ui.IconGenerator.java
com.google.maps.android.ui.RotationLayout.java
com.google.maps.android.ui.SquareTextView.java
com.sothree.slidinguppanel.SlidingUpPanelLayout.java
com.sothree.slidinguppanel.library.BuildConfig.java
com.sothree.slidinguppanel.library.BuildConfig.java
org.dklisiaris.downtown.Addresses.java
org.dklisiaris.downtown.BuildConfig.java
org.dklisiaris.downtown.FavsActivity.java
org.dklisiaris.downtown.GlobalData.java
org.dklisiaris.downtown.Intro.java
org.dklisiaris.downtown.MainActivity.java
org.dklisiaris.downtown.Manifest.java
org.dklisiaris.downtown.MapActivity.java
org.dklisiaris.downtown.MoreActivity.java
org.dklisiaris.downtown.Products.java
org.dklisiaris.downtown.SearchActivity.java
org.dklisiaris.downtown.Search.java
org.dklisiaris.downtown.SingleListItem.java
org.dklisiaris.downtown.Subcategories.java
org.dklisiaris.downtown.SubcatsAndFilters.java
org.dklisiaris.downtown.Tabs.java
org.dklisiaris.downtown.TestActivity.java
org.dklisiaris.downtown.WebViewActivity.java
org.dklisiaris.downtown.Websites.java
org.dklisiaris.downtown.actionbar.ActionBar.java
org.dklisiaris.downtown.actionbar.ScrollingTextView.java
org.dklisiaris.downtown.adapters.AddressFilterAdapter.java
org.dklisiaris.downtown.adapters.CustomAdapter.java
org.dklisiaris.downtown.adapters.CustomStringAdapter.java
org.dklisiaris.downtown.adapters.CustomSuggestionsAdapter.java
org.dklisiaris.downtown.adapters.MultiSelectionAdapter.java
org.dklisiaris.downtown.adapters.SubcatsAdapter.java
org.dklisiaris.downtown.db.Banner.java
org.dklisiaris.downtown.db.Category.java
org.dklisiaris.downtown.db.Company.java
org.dklisiaris.downtown.db.DBHandler.java
org.dklisiaris.downtown.db.DBInterface.java
org.dklisiaris.downtown.db.Image.java
org.dklisiaris.downtown.db.InitData.java
org.dklisiaris.downtown.db.Keyword.java
org.dklisiaris.downtown.db.Mapping.java
org.dklisiaris.downtown.db.Product.java
org.dklisiaris.downtown.db.QueryBuilder.java
org.dklisiaris.downtown.downloader.DownloadTask.java
org.dklisiaris.downtown.downloader.NotificationHelper.java
org.dklisiaris.downtown.helper.AccessAssets.java
org.dklisiaris.downtown.helper.AlertDialogManager.java
org.dklisiaris.downtown.helper.ConnectionDetector.java
org.dklisiaris.downtown.helper.FileCache.java
org.dklisiaris.downtown.helper.ImageLoader.java
org.dklisiaris.downtown.helper.InfoHelper.java
org.dklisiaris.downtown.helper.KeyboardUtil.java
org.dklisiaris.downtown.helper.MemoryCache.java
org.dklisiaris.downtown.helper.ShareHelper.java
org.dklisiaris.downtown.helper.UpdateConfirmDialog.java
org.dklisiaris.downtown.helper.UpdateHelper.java
org.dklisiaris.downtown.helper.Utils.java
org.dklisiaris.downtown.helper.XMLParser.java
org.dklisiaris.downtown.maps.AbstractMapActivity.java
org.dklisiaris.downtown.maps.CompanyMarker.java
org.dklisiaris.downtown.maps.DirectionsInfo.java
org.dklisiaris.downtown.maps.GMapV2Direction.java
org.dklisiaris.downtown.maps.Nearby.java
org.dklisiaris.downtown.maps.PopupAdapter.java
org.dklisiaris.downtown.providers.KeywordContract.java
org.dklisiaris.downtown.providers.KeywordProvider.java
org.dklisiaris.downtown.widgets.AspectRatioImageView.java
org.dklisiaris.downtown.widgets.CheckableRelativeLayout.java
org.dklisiaris.downtown.widgets.CustomScrollView.java
org.dklisiaris.downtown.widgets.FlipAnimator.java
org.dklisiaris.downtown.widgets.InertCheckBox.java
org.dklisiaris.downtown.widgets.MultiSpinner.java