how to adjust screen color brightness? - android

I am trying to create a screen filter applications.
so I'm looking for a way to change the color of the screen.
Looking for a lot of web sites, it is hard to find a way that I think.
First, how to gain access to the system, but is not suitable for distribution.
I think the second way to replace or overlay a color, it is not easy.
There comes a lot of pages to introduce the application.
The layout was created.
Now find a way.
I just do not see the page?
like this link :
https://play.google.com/store/apps/details?id=nu.bluelight.filter

Android Permission to Change Screen Brightness
.
<uses-permission android:name="android.permission.WRITE_SETTINGS"></uses-permission>
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<SeekBar
android:id="#+id/seekBar1"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="26dp"
android:max="10" />
</RelativeLayout>
MainActivity.java
package com.example.android_adjustbrightness;
import android.os.Bundle;
import android.provider.Settings.SettingNotFoundException;
import android.app.Activity;
import android.view.Menu;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
public class MainActivity extends Activity {
private SeekBar seekBar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
seekBar = (SeekBar) findViewById(R.id.seekBar1);
seekBar.setMax(255);
float curBrightnessValue = 0;
try {
curBrightnessValue = android.provider.Settings.System.getInt(
getContentResolver(),
android.provider.Settings.System.SCREEN_BRIGHTNESS);
} catch (SettingNotFoundException e) {
e.printStackTrace();
}
int screen_brightness = (int) curBrightnessValue;
seekBar.setProgress(screen_brightness);
seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
int progress = 0;
#Override
public void onProgressChanged(SeekBar seekBar, int progresValue,
boolean fromUser) {
progress = progresValue;
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
// Do something here,
// if you want to do anything at the start of
// touching the seekbar
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
android.provider.Settings.System.putInt(getContentResolver(),
android.provider.Settings.System.SCREEN_BRIGHTNESS,
progress);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android_adjustbrightness"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" >
</uses-permission>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.android_adjustbrightness.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

Related

How to Avoid Crashing of screen size when video is rotated

i have problems in playing my video. I have an activity with the following property in manifest
android:configChanges="orientation|keyboard|keyboardHidden|screenSize"
but everytime i change the orientation from portrait to landscape, the screen size is showing portrait. and the same thing happening for Landscape to portrait the screen size is showing landscape like the figure shown in the link.
enter image description here
manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.bdb"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
MainActivity.java
package com.example.bdb;
import android.app.Activity;
import android.content.res.Configuration;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.view.WindowManager;
import android.widget.MediaController;
import android.widget.Toast;
import android.widget.VideoView;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().addFlags(WindowManager.LayoutParams .FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
VideoView myVideoView = (VideoView)findViewById(R.id.birthdayview);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(myVideoView);
try{
String vidpath = "android.resource://" + getPackageName() + "/" + R.raw.birthday;
myVideoView.setVideoURI(Uri.parse(vidpath));
myVideoView.setMediaController(new MediaController(this));
myVideoView.requestFocus();
myVideoView.start();
}
catch (Exception e){
Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_SHORT);
}
}
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
tools:context="com.example.bdb.MainActivity" >
<VideoView
android:id="#+id/birthdayview"
android:layout_width="fill_parent"
android:layout_alignParentRight="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_height="fill_parent">
</VideoView>
any solution/suggestions to solve this problem? Thank you so much :)
By declaring android:configChanges="orientation|keyboard|keyboardHidden|screenSize" in your manifest, you took responsibility for handling all these changes. Yet, you have not implemented onConfigurationChanged to handle the configuration change for your layout. You should manually change the size of the VideoView.
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
doLayout();
}
private void doLayout() {
if (getResources().getConfiguration().orientation
== Configuration.ORIENTATION_PORTRAIT) {
// do PORTRAIT stuff
} else {
// do LANDSCAPE stuff
}
}

Flashligth Android app - feature not working on phones

I am a developer just starting out with Android.
I developed an app for Android that runs on tablet and phone which offers various services including flashlight.
I added this configuration in the manifest:
<Uses-feature android: name = "android.hardware.camera" android: required = "false" />
<Uses-feature android: name = "android.hardware.telephony" android: required = "false" />
I thought that with these two last optional features I could access the flash device when present on phone without exclude tablets to have the possibility to install the app but it doesnt work.
Where am I wrong? Can someone please help me?
The above code just give the permission for the flashLight.
You have to write a code to turnon and off the Flash
I am adding the snippet of the demo i did for turning on and offing the flash light.
MainActivity.java
package com.example.balaji.myapplication;
import android.hardware.Camera;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
public class MainActivity extends ActionBarActivity {
private Camera cam;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button turnOn = (Button)findViewById(R.id.turnOnFlashLight);
turnOn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
turnOnFlashlight();
}
});
Button turnOff = (Button)findViewById(R.id.turnOffFlashLight);
turnOff.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
turnOffFlashlight();
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public void turnOnFlashlight(){
cam = Camera.open();
Camera.Parameters p = cam.getParameters();
p.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
cam.setParameters(p);
cam.startPreview();
}
public void turnOffFlashlight(){
cam.release();
}
}
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity">
<Button
android:id="#+id/turnOnFlashLight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Turn On"
/>
<Button
android:id="#+id/turnOffFlashLight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Turn Off"
/>
</LinearLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.balaji.myapplication" >
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.FLASHLIGHT"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I am also giving the stackoverflow links for more information on this.
How to turn on FlashLight in Lollipop programmatically Android

Same xml code, different graphic layout

I am new to android development and i tried copying an xml layout from another project, but the graphic layout of that xml seems to be different from what i am getting. I have no idea what is missing in my project that I am not getting the same layout. Please help.
this is what it looks like
!1
and this is what i get after copying the exact code.
!2
my xml file
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.aditya.contentsharer"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:name=".InteriorSpottingApplication"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".InteriorListActivity"
android:label="#string/title_activity_interior_list" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="android.app.Activity" />
</activity>
<activity
android:name=".NewInteriorActivity"
android:label="#string/title_activity_new_interior" >
</activity>
</application>
</manifest>
xml code
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/fragmentContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
java code
package com.aditya.contentsharer;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import com.parse.ParseQueryAdapter;
public class InteriorListActivity extends ListActivity{
private ParseQueryAdapter<Interior> mainAdapter;
private FavoriteInteriorAdapter favoritesAdapter;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getListView().setClickable(false);
mainAdapter = new ParseQueryAdapter<Interior>(this, Interior.class);
mainAdapter.setTextKey("title");
mainAdapter.setImageKey("photo");
// Subclass of ParseQueryAdapter
favoritesAdapter = new FavoriteInteriorAdapter(this);
// Default view is all interiors
setListAdapter(mainAdapter);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_interior_list, menu);
return true;
}
/*
* Posting interiors and refreshing the list will be controlled from the Action
* Bar.
*/
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_refresh: {
updateinteriorList();
break;
}
case R.id.action_favorites: {
showFavorites();
break;
}
case R.id.action_new: {
newinterior();
break;
}
}
return super.onOptionsItemSelected(item);
}
private void updateinteriorList() {
mainAdapter.loadObjects();
setListAdapter(mainAdapter);
}
private void showFavorites() {
favoritesAdapter.loadObjects();
setListAdapter(favoritesAdapter);
}
private void newinterior() {
Intent i = new Intent(this, NewInteriorActivity.class);
startActivityForResult(i, 0);
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
// If a new post has been added, update
// the list of posts
updateinteriorList();
}
}
}
I got the solution. I removed android:theme="#style/AppTheme" from the manifest file. That worked fine for me.
I am not used to deal with ListActivities since I usually do it with a ListView in a normal activity but my first guess is that you still need to have a line like this in your onCreate() method to actually get any layout...
setContentView(R.layout.fragmentContainer);
(assuming your xml file has the same name as it's ID right?
Try putting it after the
super.onCreate(savedInstanceState);
I am not sure if it will work but try it! :)

Implementing a custom indicator with ViewPageIndicator - How can I do it to a gallery?

I'm working on a project and I managed to get to the point where I can show my images in a gallery sort of style using PagerAdapter. Now what I want to do is add an indicator to which image is on the screen and I figure that VPI could help me out - the problem is that I'm really new to code and don't know how to implement it, could someone help?
Here's a gif of what I want to achieve - the green line indicator: http://imgur.com/GgYgY8I
I made a simpler version of my project to fit in this post, here it is:
ImageAdapter.java
package com.exp.viewpagersstest1;
import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
public class ImageAdapter extends PagerAdapter {
Context ssContext;
private int[] ssImages = new int[] { R.drawable.splash1,R.drawable.splash2, R.drawable.splash3 };
ImageAdapter(Context ssContext) {
this.ssContext = ssContext;
}
#Override
public int getCount() {
return ssImages.length;
}
#Override
public boolean isViewFromObject(View ssView, Object ssObject) {
return ssView == ((ImageView) ssObject);
}
#Override
public Object instantiateItem(ViewGroup ssContainer, int ssPosition) {
ImageView ssImageView = new ImageView(ssContext);
ssImageView.setScaleType(ImageView.ScaleType.FIT_XY);
ssImageView.setImageResource(ssImages[ssPosition]);
((ViewPager) ssContainer).addView(ssImageView, 0);
return ssImageView;
}
#Override
public void destroyItem(ViewGroup ssContainer, int ssPosition,
Object ssObject) {
((ViewPager) ssContainer).removeView((ImageView) ssObject);
}
}
SSTest.java
package com.exp.viewpagersstest1;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.Menu;
public class SSTest extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sstest);
ViewPager ssViewPager = (ViewPager) findViewById(R.id.ss_view_pager);
ImageAdapter ssAdapter = new ImageAdapter(this);
ssViewPager.setAdapter(ssAdapter);
}
#Override
public boolean onCreateOptionsMenu(Menu menu){
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.sstest, menu);
return true;
}
activity_sstest.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SSTest" >
<android.support.v4.view.ViewPager
android:id="#+id/ss_view_pager"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:adjustViewBounds="true" />
</RelativeLayout>
ViewPagerSSTest1 Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.exp.viewpagersstest1"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.exp.viewpagersstest1.SSTest"
android:label="#string/app_name"
android:theme="#style/Theme.Sherlock.NoActionBar"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Thanks in advance to anyone who replies.
Was much more simple than I expected, just needed to add the following to my xml:
<com.viewpagerindicator.UnderlinePageIndicator
android:id="#+id/pageIndic"
android:layout_height="3dp"
android:layout_width="fill_parent"
android:layout_alignParentBottom="true"
app:selectedColor="#ef4154"/>
And the following to the oncreate under the java file:
UnderlinePageIndicator pageIndicator = (UnderlinePageIndicator) findViewById(R.id.pageIndic);
pageIndicator.setViewPager(ssViewPager);

I can't get android jsoup to work

Hi i need help with a tutorial i tried from ( http://xjaphx.wordpress.com/2012/02/04/android-xml-adventure-parsing-html-using-jsoup/ ). It's about jsoup but i can't get it to work i only get a lott of errors and stuff.
Here is my code:
package com.sigustgebran.appsl;
import android.os.Bundle;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import android.app.Activity;
import android.view.Menu;
import android.widget.TextView;
public class MainAct extends Activity {
//blog url
static final String BLOG_URL = "http://xjaphx.wordpress.com/";
#Override
protected void onCreate(Bundle savedInstanceState) {
//set layout view
super.onCreate(savedInstanceState);
setContentView(R.layout.act_main);
//process
try {
((TextView)findViewById(R.id.tvDisplay)).setText(getBlogStats());
} catch (Exception ex) {
((TextView)findViewById(R.id.tvDisplay)).setText("Error");
}
}
protected String getBlogStats() throws Exception {
String result = "";
//get html document structure
Document document = Jsoup.connect(BLOG_URL).get();
//select path
Elements nodeBlogStats = document.select("div#blog-stats ul li");
//check results
if(nodeBlogStats.size() > 0) {
//get value
result = nodeBlogStats.get(0).text();
}
//return
return result;
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:layout_gravity="center"
android:id="#+id/tvDisplay"
/>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sigustgebran.appsl"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.sigustgebran.appsl.MainAct"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I would be really glad if anyone could help me. Thanks
I got it to work now. I had added the jsoup library in "External jars" as he said in the tutorial, but when I deleted it and just copied it in the "libs" map instead it worked.
you have to implement AsyncTask. I think this will help you

Categories

Resources