com.hkm.listviewhkm.base.LabelBase.java Source code

Java tutorial

Introduction

Here is the source code for com.hkm.listviewhkm.base.LabelBase.java

Source

/*
 * Terms and conditions
 *
 * Preamble: This Agreement, signed on Jul 2, 2014 [hereinafter: Effective Date] governs the relationship between HKm, a private person, (hereinafter: Licensee) and HKM, a private person whose principal place of business is 945 Battery St, San Francisco, CA 94111, CA, United States (Hereinafter: Licensor). This Agreement sets the terms, rights, restrictions and obligations on using [OneCall] (hereinafter: The Software) created and owned by Licensor, as detailed herein
 * License Grant: Licensor hereby grants Licensee a Sublicensable, Assignable, Commercial with terms, Including the rights to create but not distribute derivative works, Non-exclusive license, all with accordance with the terms set forth and other legal restrictions set forth in 3rd party software used while running Software.
 * Limited: Licensee may use Software for the purpose of:
 * Running Software on Licensees Website[s] and Server[s];
 * Allowing 3rd Parties to run Software on Licensees Website[s] and Server[s];
 * Publishing Softwares output to Licensee and 3rd Parties;
 * Distribute verbatim copies of Softwares output (including compiled binaries);
 * Modify Software to suit Licensees needs and specifications.
 * Binary Restricted: Licensee may sublicense Software as a part of a larger work containing more than Software, distributed solely in Object or Binary form under a personal, non-sublicensable, limited license. Such redistribution shall be limited to unlimited codebases.
 * Assignable: Licensee may assign his rights and duties under this license as long as the party who Licensee assigns the license accepts the license in full, and provides Licensor with a written confirmation of Assignment
 * Commercial use allowed with restrictions: by agreements and terms granted by the author.
 * Including the Right to Create Derivative Works: Licensee may create derivative works based on Software, including amending Softwares source code, modifying it, integrating it into a larger work or removing portions of Software, as long as no distribution of the derivative works is made
 * With Attribution Requirements:
 * Licensor shall retain full title in Trademarks, and any trademarks and tradenames contained, including Software's names, logos, and all other intellectual property. Unless specifically stated in this license, no license shall be made to use, associate or affiliate Software with Licensee in any manner. Licensee may not use Softwares name, tradename, trademarks or logo when distributing derivative works of software to 3rd parties.
 * If Software is covered by Patents, Licensor grants Licensee a non-exclusive, worldwide, royalty-free patent license under Licensor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of Software.
 * Licensee hereby acknowledges that Software contains Licensors trade secrets and other proprietary information that has not been disclosed to the public domain. Licensee shall not disclose, reveal, make available or convey to any 3rd party portions of Software, including Softwares know-how, means of operations, algorithms, and any other proprietary information (hereinafter: Confidential Information). Licensees obligations shall remain in effect as long as Confidential Information does not (i) enter into the public domain by any voluntary act made by Licensor; or (ii) Licensee is ordered by a definite court order, or any other legal authority, to disclose Confidential Information; or (iii) Confidential Information was independently developed by a 3rd Party who was not exposed to the Software. Licensee shall require any 3rd party who sublicenses Software to sign a non-disclosure agreement no less restrictive than this license.
 * Term & Termination: The Term of this license shall be until terminated. Licensor may terminate this Agreement, including Licensees license in the case where Licensee :
 * became insolvent or otherwise entered into any liquidation process; or
 * exported The Software to any jurisdiction where licensor may not enforce his rights under this agreements in; or
 * Licensee was in breach of any of this license's terms and conditions and such breach was not cured, immediately upon notification; or
 * Licensee in breach of any of the terms of clause 2 to this license; or
 * Licensee otherwise entered into any arrangement which caused Licensor to be unable to enforce his rights under this License.
 * Payment: In consideration of the License granted under clause 2, Licensee shall pay Licensor a fee, via Credit-Card, PayPal or any other mean which Licensor may deem adequate. Failure to perform payment shall construe as material breach of this Agreement.
 * Upgrades, Updates and Fixes: Licensor may provide Licensee, from time to time, with Upgrades, Updates or Fixes, as detailed herein and according to his sole discretion. Licensee hereby warrants to keep The Software up-to-date and install all relevant updates and fixes, and may, at his sole discretion, purchase upgrades, according to the rates set by Licensor. Licensor shall provide any update or Fix free of charge; however, nothing in this Agreement shall require Licensor to provide Updates or Fixes.
 * Upgrades: for the purpose of this license, an Upgrade shall be a material amendment in The Software, which contains new features and or major performance improvements and shall be marked as a new version number. For example, should Licensee purchase The Software under version 1.X.X, an upgrade shall commence under number 2.0.0.
 * Updates: for the purpose of this license, an update shall be a minor amendment in The Software, which may contain new features or minor improvements and shall be marked as a new sub-version number. For example, should Licensee purchase The Software under version 1.1.X, an upgrade shall commence under number 1.2.0.
 * Fix: for the purpose of this license, a fix shall be a minor amendment in The Software, intended to remove bugs or alter minor features which impair the The Software's functionality. A fix shall be marked as a new sub-sub-version number. For example, should Licensee purchase Software under version 1.1.1, an upgrade shall commence under number 1.1.2.
 * Support: Software is provided under an AS-IS basis and without any support, updates or maintenance. Nothing in this Agreement shall require Licensor to provide Licensee with support or fixes to any bug, failure, mis-performance or other defect in The Software.
 * Bug Notification: Licensee may provide Licensor of details regarding any bug, defect or failure in The Software promptly and with no delay from such event; Licensee shall comply with Licensor's request for information regarding bugs, defects or failures and furnish him with information, screenshots and try to reproduce such bugs, defects or failures.
 * Feature Request: Licensee may request additional features in Software, provided, however, that (i) Licensee shall waive any claim or right in such feature should feature be developed by Licensor; (ii) Licensee shall be prohibited from developing the feature, or disclose such feature request, or feature, to any 3rd party directly competing with Licensor or any 3rd party which may be, following the development of such feature, in direct competition with Licensor; (iii) Licensee warrants that feature does not infringe any 3rd party patent, trademark, trade-secret or any other intellectual property right; and (iv) Licensee developed, envisioned or created the feature solely by himself.
 * Liability:  To the extent permitted under Law, The Software is provided under an AS-IS basis. Licensor shall never, and without any limit, be liable for any damage, cost, expense or any other payment incurred by Licensee as a result of Softwares actions, failure, bugs and/or any other interaction between The Software  and Licensees end-equipment, computers, other software or any 3rd party, end-equipment, computer or services.  Moreover, Licensor shall never be liable for any defect in source code written by Licensee when relying on The Software or using The Softwares source code.
 * Warranty:
 * Intellectual Property: Licensor hereby warrants that The Software does not violate or infringe any 3rd party claims in regards to intellectual property, patents and/or trademarks and that to the best of its knowledge no legal action has been taken against it for any infringement or violation of any 3rd party intellectual property rights.
 * No-Warranty: The Software is provided without any warranty; Licensor hereby disclaims any warranty that The Software shall be error free, without defects or code which may cause damage to Licensees computers or to Licensee, and that Software shall be functional. Licensee shall be solely liable to any damage, defect or loss incurred as a result of operating software and undertake the risks contained in running The Software on Licenses Server[s] and Website[s].
 * Prior Inspection: Licensee hereby states that he inspected The Software thoroughly and found it satisfactory and adequate to his needs, that it does not interfere with his regular operation and that it does meet the standards and scope of his computer systems and architecture. Licensee found that The Software interacts with his development, website and server environment and that it does not infringe any of End User License Agreement of any software Licensee may use in performing his services. Licensee hereby waives any claims regarding The Software's incompatibility, performance, results and features, and warrants that he inspected the The Software.
 * No Refunds: Licensee warrants that he inspected The Software according to clause 7(c) and that it is adequate to his needs. Accordingly, as The Software is intangible goods, Licensee shall not be, ever, entitled to any refund, rebate, compensation or restitution for any reason whatsoever, even if The Software contains material flaws.
 * Indemnification: Licensee hereby warrants to hold Licensor harmless and indemnify Licensor for any lawsuit brought against it in regards to Licensees use of The Software in means that violate, breach or otherwise circumvent this license, Licensor's intellectual property rights or Licensor's title in The Software. Licensor shall promptly notify Licensee in case of such legal action and request Licensees consent prior to any settlement in relation to such lawsuit or claim.
 * Governing Law, Jurisdiction: Licensee hereby agrees not to initiate class-action lawsuits against Licensor in relation to this license and to compensate Licensor for any legal fees, cost or attorney fees should any claim brought by Licensee against Licensor be denied, in part or in full.
 */

package com.hkm.listviewhkm.base;

import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.TabHost;
import android.widget.TextView;

import com.doomonafireball.betterpickers.numberpicker.NumberPickerBuilder;
import com.doomonafireball.betterpickers.numberpicker.NumberPickerDialogFragment;
import com.hkm.U.Content;
import com.hkm.datamodel.DataHandler;
import com.hkm.datamodel.Label;
import com.hkm.U.Tool;
import com.hkm.oc.preF.root.CrossCommunicate;
import com.hkm.root.Dialog.DialogCB;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * Created by Hesk on 3/7/2014.
 */
public class LabelBase extends DialogIntent implements TabHost.OnTabChangeListener, ViewPager.OnPageChangeListener,
        View.OnClickListener, View.OnKeyListener, CrossCommunicate, AdapterView.OnItemSelectedListener, DialogCB,
        NumberPickerDialogFragment.NumberPickerDialogHandler {
    final public static int START_LINE_INDEX = 41, END_LINE_INDEX = 60, START_SHARP_INDEX = 0, END_SHARP_INDEX = 40;
    protected TabHost mTabHost;
    protected ViewPager mViewPager;
    protected HashMap<String, TabInfo> mapTabInfo = new HashMap<String, TabInfo>();
    protected ArrayList<Fragment> fragmentsList;
    protected String[] tabs_holder = { "Line", "Cable #", "Map Use" };
    protected Spinner areaspinner;
    protected TextView label_display_field;
    protected Button display_label_but;
    protected NumberPickerBuilder mNumberPickerBuilder;
    protected LineFactory mLineFactory;
    protected boolean hasChanges;

    @Override
    public void onPickList(int index_id, int RoleType) {

    }

    @Override
    public void onDialogPositiveClick(DialogFragment dialog) {

    }

    @Override
    public void onDialogNegativeClick(DialogFragment dialog) {

    }

    @Override
    public void onDialogNeutral(DialogFragment dialog) {

    }

    @Override
    public void onDialogNumberSet(int i, int i2, double v, boolean b, double v2) {

    }

    @Override
    public void onClick(View view) {

    }

    @Override
    public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {

    }

    @Override
    public void onNothingSelected(AdapterView<?> adapterView) {

    }

    @Override
    public boolean onKey(View view, int i, KeyEvent keyEvent) {
        return false;
    }

    /**
     * This method will be invoked when the current page is scrolled, either as part
     * of a programmatically initiated smooth scroll or a user initiated touch scroll.
     *
     * @param position             Position index of the first page currently being displayed.
     *                             Page position+1 will be visible if positionOffset is nonzero.
     * @param positionOffset       Value from [0, 1) indicating the offset from the page at position.
     * @param positionOffsetPixels Value in pixels indicating the offset from position.
     */
    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    /**
     * This method will be invoked when a new page becomes selected. Animation is not
     * necessarily complete.
     *
     * @param position Position index of the new selected page.
     */
    @Override
    public void onPageSelected(int position) {

    }

    /**
     * Called when the scroll state changes. Useful for discovering when the user
     * begins dragging, when the pager is automatically settling to the current page,
     * or when it is fully stopped/idle.
     *
     * @param state The new scroll state.
     * @see android.support.v4.view.ViewPager#SCROLL_STATE_IDLE
     * @see android.support.v4.view.ViewPager#SCROLL_STATE_DRAGGING
     * @see android.support.v4.view.ViewPager#SCROLL_STATE_SETTLING
     */
    @Override
    public void onPageScrollStateChanged(int state) {

    }

    @Override
    public void onTabChanged(String s) {

    }

    /**
     * Line Factory to generate the result
     */
    public class LineFactory {
        private String dLetter, dNumeric, display_big_button_label;
        private int letterIntrinsic, datastorage_index, lineLabelInt;
        private boolean can_exit_complete;
        private Label in_lab;

        public LineFactory() {
            can_exit_complete = false;
            dLetter = dNumeric = display_big_button_label = "";
        }

        /**
         * update the letter intrinsic here
         *
         * @param n_Letter_Intrinsic
         * @return
         */
        public LineFactory updateI(int n_Letter_Intrinsic) {
            letterIntrinsic = n_Letter_Intrinsic;
            return this;
        }

        /**
         * updating the line intrinsic
         *
         * @param line_int
         * @return
         */
        public LineFactory update_line_I(int line_int) {
            lineLabelInt = line_int;
            return this;
        }

        /**
         * update the line letter label here
         *
         * @param update_the_letter_label
         * @return
         */
        public LineFactory updateL(String update_the_letter_label) {
            dLetter = update_the_letter_label;
            return this;
        }

        /**
         * this is only used for updating for the listing. It can handle both selection of line and feature records
         *
         * @param n_letterIntrinsic
         * @return
         */
        public LineFactory updateMechanicallyByIntrinsicN(int n_letterIntrinsic) {
            letterIntrinsic = n_letterIntrinsic;
            if (!DataHandler.isSharp(n_letterIntrinsic)) {
                lineLabelInt = n_letterIntrinsic;
            }
            dLetter = DataHandler.get_letter_reference_by_index_id(n_letterIntrinsic);
            return this;
        }

        /**
         * return the letter intrinsic of the row
         *
         * @return
         */
        public int getLetterIntrinsic() {
            return letterIntrinsic;
        }

        /**
         * update the label number
         * takes int
         *
         * @param updatet_the_dNumeric
         * @return
         */
        public LineFactory updateN(int updatet_the_dNumeric) {
            dNumeric = String.valueOf(updatet_the_dNumeric);
            return this;
        }

        /**
         * taking string
         *
         * @param updatet_the_dNumeric
         * @return
         */
        public LineFactory updateN(String updatet_the_dNumeric) {
            dNumeric = updatet_the_dNumeric;
            return this;
        }

        private Label prepare_new_label() {
            final String s = dLetter + dNumeric + DataHandler.sharpOut(letterIntrinsic);
            final Label lab = new Label();
            lab.set_display_big_button_label(s);
            lab.set_dLetter(dLetter);
            lab.set_dNumeric(dNumeric);
            lab.set_letterIntrinsic(letterIntrinsic);
            lab.set_lineLabelInt(lineLabelInt);
            lab.refresh_data(getBaseContext());
            return lab;
        }

        /**
         * save the current settings
         */
        public void save() {
            if (in_lab == null) {
                in_lab = prepare_new_label();
            }
            Content.current_sketch_map.update_routenode_label(datastorage_index, in_lab);
        }

        /**
         * constuct the returning data here.
         *
         * @return
         */
        public Bundle dataWrite() {

            //convert data from bundle to json
            /*  JSONObject json = new JSONObject();
              Set<String> keys = b.keySet();
              for (String key : keys) {
            try {
                json.put(key, b.get(key));
            } catch (JSONException e) {
                //Handle exception here
            }
              }*/

            final Bundle b = new Bundle();
            Log.d("LINE FACTORY OUTPUT", b.toString());
            return b;
        }

        public boolean datawrite_by_other_ref_radius(int selected_pos) {
            return DataHandler.result_update_from_the_previous_item(selected_pos - 1, datastorage_index);
        }

        public void invalidate() {
            final boolean a = dLetter.length() > 0;
            final boolean b = dNumeric.length() > 0;
            if (!a && !b) {
                display_big_button_label = "";
                can_exit_complete = false;
            } else if (!a && b) {
                display_big_button_label = "_" + dNumeric;
                can_exit_complete = false;
            } else if (a && !b) {
                display_big_button_label = dLetter + "__" + DataHandler.sharpOut(letterIntrinsic);
                can_exit_complete = false;
            } else if (a && b) {
                display_big_button_label = dLetter + dNumeric + DataHandler.sharpOut(letterIntrinsic);
                can_exit_complete = true;
                in_lab = prepare_new_label();
            }
            label_display_field.setText(display_big_button_label);
            if (a && in_lab != null) {
                label_display_field.setTextColor(in_lab.get_paint_color());
            }
        }

        public LineFactory set_record_plan_index(int label_index) {
            datastorage_index = label_index;
            return this;
        }

        public boolean exitenable() {
            if (!can_exit_complete) {
                Tool.trace(getBaseContext(), "Please complete this label");
                return false;
            } else {
                return true;
            }
        }
    }

    /**
     * @author mwho
     *         Maintains extrinsic info of a tab's construct
     */
    protected class TabInfo {
        public String tag;
        private Class<?> clss;
        private Bundle args;
        private Fragment fragment;

        public TabInfo(String tag, Class<?> clazz, Bundle args) {
            this.tag = tag;
            this.clss = clazz;
            this.args = args;
        }
    }

    /**
     * A simple factory that returns dummy views to the Tabhost
     *
     * @author mwho
     */
    public class TabFactory implements TabHost.TabContentFactory {

        private final Context mContext;

        /**
         * @param context
         */
        public TabFactory(Context context) {
            mContext = context;
        }

        /**
         * (non-Javadoc)
         *
         * @see android.widget.TabHost.TabContentFactory#createTabContent(java.lang.String)
         */
        @Override
        public View createTabContent(String tag) {
            View v = new View(mContext);
            v.setMinimumWidth(0);
            v.setMinimumHeight(0);
            return v;
        }

    }
}