Java Code Examples for org.appcelerator.titanium.TiApplication#getInstance()

The following examples show how to use org.appcelerator.titanium.TiApplication#getInstance() . 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: ActionbarextrasModule.java    From actionbarextras with MIT License 6 votes vote down vote up
/**
 * Sets Up icon color
 * @param obj
 */
private void handleSetUpColor(String color){
	
	ActionBar actionBar = getActionBar();
	
	try {
		TiApplication appContext = TiApplication.getInstance();
		AppCompatActivity _activity = (AppCompatActivity) appContext.getCurrentActivity();

		final int res_id = TiRHelper.getResource("drawable.abc_ic_ab_back_material", true);
		final Drawable upArrow = ContextCompat.getDrawable(_activity, res_id);

		upArrow.setColorFilter(TiConvert.toColor(color), PorterDuff.Mode.SRC_ATOP);
		actionBar.setHomeAsUpIndicator(upArrow);
	}catch(Exception e){
		Log.e(TAG, e.toString());
	}
}
 
Example 2
Source File: NovarumbluetoothModule.java    From NovarumBluetooth with MIT License 6 votes vote down vote up
@Kroll.method
public boolean searchDevices()
{
	Log.d(TAG, "searchDevices called");
	
	//Halilk: if not enabled, enable bluetooth
	enableBluetooth();
	
	//Get Current activity//
	TiApplication appContext = TiApplication.getInstance();
	Activity activity = appContext.getCurrentActivity();		
	
       IntentFilter intentFilter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
       activity.registerReceiver(myReceiver, intentFilter);
       bluetoothAdapter.cancelDiscovery(); //cancel if it's already searching
       bluetoothAdapter.startDiscovery();		

	return true;
}
 
Example 3
Source File: ActionbarextrasModule.java    From actionbarextras with MIT License 5 votes vote down vote up
/**
 * returns the height of the Actionbar as absolute pixels
 * @return int	actionbar height
 */
@Kroll.getProperty @Kroll.method
public int getActionbarHeight() {
	TiApplication appContext = TiApplication.getInstance();
	final TypedArray styledAttributes = appContext.getTheme().obtainStyledAttributes(
               new int[] { android.R.attr.actionBarSize }
       );
	int mActionBarSize = (int) styledAttributes.getDimension(0, 0);
	styledAttributes.recycle();
	return mActionBarSize;
}
 
Example 4
Source File: NovarumbluetoothModule.java    From NovarumBluetooth with MIT License 5 votes vote down vote up
@Kroll.method
public void makeDiscoverable() 
{	
	if(bluetoothAdapter.getScanMode() != BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE)
	{		
		TiApplication appContext = TiApplication.getInstance();
		Activity activity = appContext.getCurrentActivity();
		
		Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
	    discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);
	    activity.startActivity(discoverableIntent);
	}
}
 
Example 5
Source File: ImageViewerActivity.java    From titanium-imagepicker with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Intent intent = getIntent();
    imagesAdapter = intent.getExtras().getParcelableArrayList(Defaults.Params.IMAGES);

    Defaults.setupInitialValues(getApplicationContext(), intent);

    if (!Defaults.ACTIVITY_THEME.isEmpty()) {
 		setTheme(Utils.getR("style." + Defaults.ACTIVITY_THEME));
 }

    setupIds();
    setContentView(frame_layout);

    isShapeCircle = Defaults.SHAPE_CIRCLE == Defaults.SHAPE;

    if (Build.VERSION.SDK_INT >= 21) {
        Window window = getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

        if (!Defaults.STATUS_BAR_COLOR.isEmpty()) {
        	window.setStatusBarColor(TiConvert.toColor(Defaults.STATUS_BAR_COLOR));
        }

        window.setBackgroundDrawable(TiConvert.toColorDrawable(Defaults.BACKGROUND_COLOR));
    }

    ActionBar actionBar = getSupportActionBar();

    if (actionBar != null) {
    		if (!Defaults.BAR_COLOR.isEmpty()) {
    			actionBar.setBackgroundDrawable(TiConvert.toColorDrawable(Defaults.BAR_COLOR));
        }

        actionBar.setDisplayShowHomeEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setDisplayShowTitleEnabled(false);
        actionBar.setDisplayShowTitleEnabled(true);
        actionBar.setTitle(Defaults.TITLE);
    } else {
 		Log.e(TAG, Defaults.ACTION_BAR_ERROR_MSG);
 }

    mRecyclerView = new RecyclerView(TiApplication.getInstance());
    mRecyclerView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    mRecyclerView.setLayoutManager(new GridLayoutManager(ImageViewerActivity.this, Defaults.GRID_SIZE));

    FrameLayout frame_container = (FrameLayout) findViewById(frame_layout_id);
    frame_container.addView(mRecyclerView);
    frame_container.setBackgroundColor(TiConvert.toColor(Defaults.BACKGROUND_COLOR));

    adapterSet = new PhotoAdapter(imagesAdapter);
    mRecyclerView.setAdapter(adapterSet);

    if ( (1 == Defaults.SHOW_DIVIDER) && (!isShapeCircle) ) {
    	mRecyclerView.addItemDecoration(new DividerDecoration());
    }

    setupGlideOptions(); // set glide-options to apply on image
}
 
Example 6
Source File: ImagePickerActivity.java    From titanium-imagepicker with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    Defaults.setupInitialValues(getApplicationContext(), getIntent());

    if (!Defaults.ACTIVITY_THEME.isEmpty()) {
    		setTheme(Utils.getR("style." + Defaults.ACTIVITY_THEME));
    }

    setupIds();
    setContentView(main_layout_id);

    isMultipleSelection = (1 != Defaults.MAX_IMAGE_SELECTION);
    isShapeCircle = Defaults.SHAPE_CIRCLE == Defaults.SHAPE;

    if (Build.VERSION.SDK_INT >= 21) {
        Window window = getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

        if (!Defaults.STATUS_BAR_COLOR.isEmpty()) {
        	window.setStatusBarColor(TiConvert.toColor(Defaults.STATUS_BAR_COLOR));
        }

        window.setBackgroundDrawable(TiConvert.toColorDrawable(Defaults.BACKGROUND_COLOR));
    }

    ActionBar actionBar = getSupportActionBar();

    if (actionBar != null) {
    		if (!Defaults.BAR_COLOR.isEmpty()) {
    			actionBar.setBackgroundDrawable(TiConvert.toColorDrawable(Defaults.BAR_COLOR));
        }

        actionBar.setDisplayShowHomeEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setDisplayShowTitleEnabled(false);
        actionBar.setDisplayShowTitleEnabled(true);
        actionBar.setTitle(Defaults.TITLE);

    } else {
    		Log.e(TAG, Defaults.ACTION_BAR_ERROR_MSG);
    }


    mRecyclerView = new RecyclerView(TiApplication.getInstance());
    mRecyclerView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    mRecyclerView.setLayoutManager(new GridLayoutManager(ImagePickerActivity.this, Defaults.GRID_SIZE));

    FrameLayout frame_container = (FrameLayout) findViewById(container);
    frame_container.addView(mRecyclerView);
    frame_container.setBackgroundColor(TiConvert.toColor(Defaults.BACKGROUND_COLOR));

    adapterSet = new PhotoAdapter(adapter);
    mRecyclerView.setAdapter(adapterSet);

    if ( (1 == Defaults.SHOW_DIVIDER) && (!isShapeCircle) ) {
    	mRecyclerView.addItemDecoration(new DividerDecoration());
    }

    setupGlideOptions(); // set glide-options to apply on image

    // Get gallery photos in a new UI thread like AsyncTask to update UI changes properly
    new FetchImages().execute();
}
 
Example 7
Source File: ImageViewerActivity.java    From titanium-imagepicker with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Intent intent = getIntent();
    imagesAdapter = intent.getExtras().getParcelableArrayList(Defaults.Params.IMAGES);

    Defaults.setupInitialValues(getApplicationContext(), intent);

    if (!Defaults.ACTIVITY_THEME.isEmpty()) {
 		setTheme(Utils.getR("style." + Defaults.ACTIVITY_THEME));
 }

    setupIds();
    setContentView(frame_layout);

    isShapeCircle = Defaults.SHAPE_CIRCLE == Defaults.SHAPE;

    if (Build.VERSION.SDK_INT >= 21) {
        Window window = getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

        if (!Defaults.STATUS_BAR_COLOR.isEmpty()) {
        	window.setStatusBarColor(TiConvert.toColor(Defaults.STATUS_BAR_COLOR));
        }

        window.setBackgroundDrawable(TiConvert.toColorDrawable(Defaults.BACKGROUND_COLOR));
    }

    ActionBar actionBar = getSupportActionBar();

    if (actionBar != null) {
    		if (!Defaults.BAR_COLOR.isEmpty()) {
    			actionBar.setBackgroundDrawable(TiConvert.toColorDrawable(Defaults.BAR_COLOR));
        }

        actionBar.setDisplayShowHomeEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setDisplayShowTitleEnabled(false);
        actionBar.setDisplayShowTitleEnabled(true);
        actionBar.setTitle(Defaults.TITLE);
    } else {
 		Log.e(TAG, Defaults.ACTION_BAR_ERROR_MSG);
 }

    mRecyclerView = new RecyclerView(TiApplication.getInstance());
    mRecyclerView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    mRecyclerView.setLayoutManager(new GridLayoutManager(ImageViewerActivity.this, Defaults.GRID_SIZE));

    FrameLayout frame_container = (FrameLayout) findViewById(frame_layout_id);
    frame_container.addView(mRecyclerView);
    frame_container.setBackgroundColor(TiConvert.toColor(Defaults.BACKGROUND_COLOR));

    adapterSet = new PhotoAdapter(imagesAdapter);
    mRecyclerView.setAdapter(adapterSet);

    if ( (1 == Defaults.SHOW_DIVIDER) && (!isShapeCircle) ) {
    	mRecyclerView.addItemDecoration(new DividerDecoration());
    }

    setupGlideOptions(); // set glide-options to apply on image
}
 
Example 8
Source File: ImagePickerActivity.java    From titanium-imagepicker with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    Defaults.setupInitialValues(getApplicationContext(), getIntent());

    if (!Defaults.ACTIVITY_THEME.isEmpty()) {
    		setTheme(Utils.getR("style." + Defaults.ACTIVITY_THEME));
    }

    setupIds();
    setContentView(main_layout_id);

    isMultipleSelection = (1 != Defaults.MAX_IMAGE_SELECTION);
    isShapeCircle = Defaults.SHAPE_CIRCLE == Defaults.SHAPE;

    if (Build.VERSION.SDK_INT >= 21) {
        Window window = getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

        if (!Defaults.STATUS_BAR_COLOR.isEmpty()) {
        	window.setStatusBarColor(TiConvert.toColor(Defaults.STATUS_BAR_COLOR));
        }

        window.setBackgroundDrawable(TiConvert.toColorDrawable(Defaults.BACKGROUND_COLOR));
    }

    ActionBar actionBar = getSupportActionBar();

    if (actionBar != null) {
    		if (!Defaults.BAR_COLOR.isEmpty()) {
    			actionBar.setBackgroundDrawable(TiConvert.toColorDrawable(Defaults.BAR_COLOR));
        }

        actionBar.setDisplayShowHomeEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setDisplayShowTitleEnabled(false);
        actionBar.setDisplayShowTitleEnabled(true);
        actionBar.setTitle(Defaults.TITLE);

    } else {
    		Log.e(TAG, Defaults.ACTION_BAR_ERROR_MSG);
    }


    mRecyclerView = new RecyclerView(TiApplication.getInstance());
    mRecyclerView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    mRecyclerView.setLayoutManager(new GridLayoutManager(ImagePickerActivity.this, Defaults.GRID_SIZE));

    FrameLayout frame_container = (FrameLayout) findViewById(container);
    frame_container.addView(mRecyclerView);
    frame_container.setBackgroundColor(TiConvert.toColor(Defaults.BACKGROUND_COLOR));

    adapterSet = new PhotoAdapter(adapter);
    mRecyclerView.setAdapter(adapterSet);

    if ( (1 == Defaults.SHOW_DIVIDER) && (!isShapeCircle) ) {
    		mRecyclerView.addItemDecoration(new DividerDecoration());
    }

    setupGlideOptions(); // set glide-options to apply on image

    // Get gallery photos in a new UI thread like AsyncTask to update UI changes properly
    new FetchImages().execute();
}
 
Example 9
Source File: NovarumbluetoothModule.java    From NovarumBluetooth with MIT License 4 votes vote down vote up
@Kroll.method
public boolean connect(String devicemac)
{
	if(devicemac == null)
	   return false;
	
	//Check if we should use the service//
	if(useService)
	{
		
		//Start Service//
		try
		{
			//Get Current activity//
			TiApplication appContext = TiApplication.getInstance();
			Activity activity = appContext.getCurrentActivity();
			
			BluetoothServiceIntent = new TiIntentWrapper(new Intent(activity,BluetoothService.class));
			BluetoothServiceIntent.getIntent().putExtra("MacAddress",devicemac);
			appContext.startService(BluetoothServiceIntent.getIntent());
			
			return true;
		}
		catch(Exception e)
		{
			Log.w(TAG,"error on creating bluetooth service: "+e.getMessage());
			return false;					
		}
		
		
	}
	else
	{		
		bluetoothDevice = bluetoothAdapter.getRemoteDevice(devicemac);
		
		if (bluetoothDevice.getBondState() == BluetoothDevice.BOND_NONE) 
		{
			if(pairDevice(bluetoothDevice))
			{
				
				return socketConnect(bluetoothDevice);
			}
			else
			{
				postError("Could not pair device");
				return false;
			}
		}
		else
		{
			return socketConnect(bluetoothDevice);				
		}
	}
}
 
Example 10
Source File: BluetoothService.java    From NovarumBluetooth with MIT License 4 votes vote down vote up
private void PostReceivedData(String data)
{
	if(data == null)
		return;
	
	//Activity can be closed, open the activity//
	TiApplication appContext = TiApplication.getInstance();
	Activity activity = appContext.getRootOrCurrentActivity();
	
	final TiIntentWrapper barcodeIntent = new TiIntentWrapper(new Intent(activity,appContext.getRootOrCurrentActivity().getClass()));
	
	try
	{			
		barcodeIntent.getIntent().putExtra("BluetoothData",data);
		appContext.startActivity(barcodeIntent.getIntent());
	}
	catch(Exception e)
	{
		Log.w(TAG,"Opening activity error on Service-PostReceivedData: "+e.getMessage());
		e.printStackTrace();
		
		//Then activity is background, try setting the flag//
		barcodeIntent.getIntent().setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		try
		{
			appContext.startActivity(barcodeIntent.getIntent());
		}
		catch(Exception e2)
		{
			Log.w(TAG,"Opening activity error on Service-PostReceivedData: "+e.getMessage());
			e.printStackTrace();				
		}
		
	}
	
	
	//Send the data//
	KrollDict receivedict = new KrollDict();
	
	receivedict.put("data", data);
	NovarumbluetoothModule.sendEvent("nb_onReceiveData", receivedict);		
	
	
	
}