Android Open Source - ItopMobile Itop Config






From Project

Back to project page ItopMobile.

License

The source code is released under:

GNU General Public License

If you think the Android project ItopMobile 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

// Copyright (C) 2011-2013 ITOMIG GmbH
///*from  w ww  . j a  v  a 2  s.c  om*/
//   This file is part of iTopMobile.
//
//   iTopMobile is free software; you can redistribute it and/or modify  
//   it under the terms of the GNU General Public License as published by
//   the Free Software Foundation, either version 3 of the License, or
//   (at your option) any later version.
//
//   iTopMobile is distributed in the hope that it will be useful,
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   GNU General Public License for more details.
//
//   You should have received a copy of the GNU General Public License
//   along with iTopMobile. If not, see <http://www.gnu.org/licenses/>

package de.itomig.itoplib;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.apache.http.message.BasicNameValuePair;
import de.itomig.itoplib.cmdb.InternalTask;
import de.itomig.itoplib.cmdb.ItopTicket;
import de.itomig.itoplib.cmdb.Organization;
import de.itomig.itoplib.cmdb.Person;
import android.annotation.SuppressLint;
import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Log;

@SuppressLint("UseSparseArrays")
public class ItopConfig extends Application {
  // DEBUG must be false for all versions released to android market
  // also remove    android:debuggable="true"  in the AndroidManifest.xml
  public static  boolean debug = true;
  // corporate version with URL check and update from itomig.de
  // or Android market version with update from market

  
  public static final int HTTP_STATUS_OK=200;

  public static final String KEY_URL = "urlPref";
  public static final String KEY_LOGIN = "loginPref";
  public static final String KEY_PASSWORD = "passwordPref";
  public static final String KEY_SSL = "sslPref";
  public static final String KEY_ITIL_TICKETS = "itilTicketsPref";
   public static final String KEY_TASKS = "taskPref";
  public static final String KEY_NOTIFY = "notifyPref";
  public static final String KEY_QUERY_NOTIFY = "queryNotifyPref";

  public static final String STATUS_ASSIGNED = "assigned";   // must match to iTop installation

  public static final String ERROR = "error";

  public static final String TAG="ITOP";
  public static final int INVALID_ID=0; // used for invalid people or ticket id.

  public static Context itopAppContext;

  public static final int NOTIFY_NO=0;
  public static final int NOTIFY_NEW=1;   
  public static final int NOTIFY_UPDATE=2;
  
  public static final int NOTIFICATION_ID_INCIDENT=1; 

  // default values point to DEMO server 
  public static String DEMO_URL="www.itomig.de/itop-demo20";
  public static String DEMO_LOGIN="admin";
  public static String DEMO_PASSWORD="1234admi";
  public static boolean DEMO_SSL=true;

  public static final int BACKGROUND_INTERVAL_MIN = 10;
  public static final int DISPLAY_REFRESH_SECS = 120;
  

  @SuppressWarnings("rawtypes")
  public static Class itopmobileactivity = null;

  // used in TicketActivity 
  public static ArrayList<ItopTicket> tickets = new ArrayList<ItopTicket>();
  public static ArrayList<String> ticketsText = new ArrayList<String>();
  
  
  public static List<InternalTask> tasks = new ArrayList<InternalTask>();
  public static ArrayList<String> tasksText = new ArrayList<String>();
  
  public static ArrayList<Organization> orgs = new ArrayList<Organization>();
  public static ArrayList<Person> persons = new ArrayList<Person>();

  public static HashMap<Integer,Person> personLookup = new HashMap<Integer,Person>();  
  public static HashMap<Integer,String> organizationLookup = new HashMap<Integer,String>();  
  public static long personLookupTime = 0L;
  public static long organizationLookupTime = 0L;
  
  public static String[] prioStrings;  // language dependent, read from arrays.xml
  
  public static void init(boolean debugflag, boolean demoflag, Context context, Class itopmob) {

    debug = debugflag;

    Log.i(TAG, "ItopLib initialized - debug="+debug);

    itopmobileactivity = itopmob;  // used for menu in SearchActivity

    itopAppContext = context; // Application Context for later use in static functions.
    
    boolean result1, result2;
    result1= Cache.getCachePersons(itopAppContext);
    result2= Cache.getCacheOrgs(itopAppContext);
    
    if ((result1== false) || (result2 == false)) {
      //TODO make static and separate persons and orgs
      PersonAndOrgsLookup pl = new PersonAndOrgsLookup();
      pl.update();
    }
  }

  public static Context getItopAppContext() {
    // for later use in some static functions
    return itopAppContext;
  }

  public static int getRefreshRateSeconds() {
    return DISPLAY_REFRESH_SECS;
  }

  public static String getItopUrl() {

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(itopAppContext); 
    String url =  (prefs.getString(KEY_URL, DEMO_URL)).trim() ;
    if ((url.length()>3) && (url.charAt(url.length()-1) == '/')) {  // remove trailing slash in url, if there is one
       url = url.substring(0,url.length()-1);
     }
    boolean ssl_enabled = prefs.getBoolean(KEY_SSL,  DEMO_SSL);

    if (ssl_enabled) {
      return "https://"+url;
    } else {
      return "http://"+url;
    }

  }

  public static String getItopCredentials() {

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(itopAppContext); 
    String login  = prefs.getString(KEY_LOGIN, DEMO_LOGIN).trim();
    String password  =  prefs.getString(KEY_PASSWORD, DEMO_PASSWORD).trim() ;

    return "auth_user="+login+"&auth_pwd="+password;

  }
   
  public static BasicNameValuePair getItopUserNameValuePair() {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(itopAppContext); 
    String login  = prefs.getString(KEY_LOGIN, DEMO_LOGIN).trim();
    return new BasicNameValuePair ("auth_user",login);
  }
  
  public static BasicNameValuePair getItopPwdNameValuePair() {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(itopAppContext); 
    String password  =  prefs.getString(KEY_PASSWORD, DEMO_PASSWORD).trim() ;
    return new BasicNameValuePair ("auth_pwd",password);
  }
  
  public static int getItopNotifySetting() {

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(itopAppContext); 
    int mNotifyCondition = Integer.valueOf(prefs.getString(KEY_NOTIFY,"0"));

    return mNotifyCondition;

  }
  
  public static boolean isEnabledlITILTicket () {

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(itopAppContext); 
    boolean itil = prefs.getBoolean(KEY_ITIL_TICKETS,true);

    return itil;

  }
  
  public static boolean isEnabledlTasks () {

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(itopAppContext); 
    boolean itil = prefs.getBoolean(KEY_TASKS,true);

    return itil;

  }
  
  public static int getNumericalPriority(String prio){
    // the prio string is language dependent!!
     
     int numPrio = INVALID_ID;
     for (int i=0; i < prioStrings.length; i++) {
       if (prio.equals(prioStrings[i])) {
         numPrio=i+1;
         break;
       }
     }
     return numPrio;
  }
}




Java Source Code List

de.itomig.itoplib.AboutActivity.java
de.itomig.itoplib.AddTaskActivity.java
de.itomig.itoplib.AlarmReceiver.java
de.itomig.itoplib.BackgroundCheck.java
de.itomig.itoplib.BootReceiver.java
de.itomig.itoplib.Cache.java
de.itomig.itoplib.DataConnection.java
de.itomig.itoplib.GetItopData.java
de.itomig.itoplib.GetItopJSON.java
de.itomig.itoplib.HelpdeskActivity.java
de.itomig.itoplib.IncidentActivity.java
de.itomig.itoplib.InternalTaskActivity.java
de.itomig.itoplib.ItopConfig.java
de.itomig.itoplib.ItopUtils.java
de.itomig.itoplib.MainActivity.java
de.itomig.itoplib.MyActivity.java
de.itomig.itoplib.PersonAndOrgsLookup.java
de.itomig.itoplib.Preferences.java
de.itomig.itoplib.SearchActivity.java
de.itomig.itoplib.TaskAdapter.java
de.itomig.itoplib.TaskDetailActivity.java
de.itomig.itoplib.TicketAdapter.java
de.itomig.itoplib.TicketDetailActivity.java
de.itomig.itoplib.cmdb.CMDBObject.java
de.itomig.itoplib.cmdb.InternalTask.java
de.itomig.itoplib.cmdb.ItopTicket.java
de.itomig.itoplib.cmdb.Organization.java
de.itomig.itoplib.cmdb.Person.java
de.itomig.itoplib.cmdb.XmlResult.java
de.itomig.itopmobile.ItopApplication.java
de.itomig.itopmobile.ItopMobileActivity.java