I am using Toolbar from Appcompat with ActionMode. The ActionMode overlays the Toolbar. Now, if i click on an empty Space in the ActionMode an underlying ActionButton from the Toolbar handles the ClickEvent.
Is this normal behaviour? How can i prevent this behaviour?
((ActionBarActivity) getActivity()).getSupportActionBar().startActionMode(new ActionMode.Callback() {
#Override
public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
actionMode.getMenuInflater().inflate(R.menu.actionmode, menu);
MenuItem menuItem = menu.findItem(R.id.number);
MenuItem menuItem1 = menu.findItem(R.id.action_edit);
TextView textView = (TextView) menuItem.getActionView();
ImageButton imageButton = (ImageButton) menuItem1.getActionView();
imageButton.setBackgroundResource(R.drawable.ic_action_edit);
textView.setText("0 selected");
// Return true so that the action mode is shown
return true;
}
#Override
public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {
// As we do not need to modify the menu before displayed, we return false.
return false;
}
#Override
public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
// Similar to menu handling in Activity.onOptionsItemSelected()
switch (menuItem.getItemId()) {
case R.id.action_delete:
// Some remove functionality
return true;
}
return true;
}
#Override
public void onDestroyActionMode(ActionMode actionMode) {
// Allows you to be notified when the action mode is dismissed
}
});
XML for my ActionMode in /res/values/menu
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/number"
android:title="number"
android:actionViewClass="android.widget.TextView"/>
<item android:id="#+id/action_edit"
android:title="edit"
android:actionViewClass="android.widget.ImageButton"/>
<item android:id="#+id/action_delete"
android:title="delete"
android:icon="#drawable/ic_action_delete"/>
</menu>
You will need to set the action mode layout to be clickable.
First set the custom Theme for entire application or a single Activity in the AndroidManifest file:
<application android:theme="#style/Theme.CustomTheme">
In themes.xml resource file set the new actionModeStyle for your theme:
<style name="Theme.CustomTheme" parent="Theme.AppCompat.NoActionBar">
<item name="actionModeStyle">#style/action_mode_style</item>
</style>
Then your action_mode_style should have android:clickable set to true
<style name="action_mode_style" parent="#style/Widget.AppCompat.ActionMode">
<item name="android:clickable">true</item>
</style>
Related
i have placed a textview and a toggle button into a list view by using the following xml file and i have used an arrayadapter to set it on to my layout, my problem is when i scroll down in the list view by unchecking a few toggle buttons (which are all set to be checked by default), they go back to default state and few others change state. As i want to fetch the state of the toggle button in my later stages its very important to stick on to the state that ive assigned to the toggle button. Please help to resolve this problem. Here are my xml file and the java code i use to set it on to the adapter. thank you in prior...
xml file that is named listdecor is included here
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/lvlistdecor"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000"
android:orientation="horizontal"
android:weightSum="2" >
<TextView
android:id="#+id/tvlistdecor"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.5"
android:ellipsize="marquee"
android:singleLine="true"
android:text="sample"
android:textColor="#FFFFFF"
android:textSize="24sp"
android:typeface="sans" />
<CheckBox
android:id="#+id/cbusn_checked"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="6sp"
android:layout_weight="0.5"
android:checked="true"
android:focusable="false"
android:padding="10dp" />
</LinearLayout>
Sir i made certain changes and also included the custom adapter to the listview and also changed to CheckBox instead of toggle buttons. but now the entire list view is not visible on my emulator. i've included my edited java class and xml file, please suggest me the changes, thank you...
The modified java code is included here
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE); // Setting the window to full screen Step 1
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN); // Setting the window to full screen Step 2
setContentView(R.layout.attendance5);
facid = (TextView) findViewById(R.id.tvfacid);
facname = (TextView) findViewById(R.id.tvfacname);
subjectchosen = (TextView) findViewById(R.id.tvsubject);
// llattendlist = (LinearLayout)findViewById(R.id.llattendlist);
String Uid = getIntent().getStringExtra("Uid");
facid.setText(Uid);
String Name = getIntent().getStringExtra("Name");
facname.setText(Name);
String Sub = getIntent().getStringExtra("Sub");
subjectchosen.setText(Sub);
Attendusn = getIntent().getExtras();
if(Attendusn!=null)
{
AttendStud_usn = (ArrayList<String>)Attendusn.getStringArrayList("AttendStud_usn");
}
String AttendLen = String.valueOf(AttendStud_usn.size());
//int flag = 0 ;
//subjectchosen.setText(String.valueOf(AttendStud_usn));
myListView = (ListView) findViewById(R.id.lvnames);
// myListView.setAdapter(new ArrayAdapter<String>(this, R.layout.listdecoration,R.id.tvlistdecor, AttendStud_usn));
//ArrayAdapter<String> MyAdapter= new ArrayAdapter<String>(this,R.layout.listdecoration, R.id.tvlistdecor,AttendStud_usn);
//myListView.setAdapter(MyAdapter);
myListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View item, int position,
long id) {
// TODO Auto-generated method stub
Stud_usn usn= MyAdapter.getItem(position);
usn.toggleChecked();
Stud_usnViewHolder vh_usn= (Stud_usnViewHolder) item.getTag();
vh_usn.getCheckBox().setChecked(usn.isChecked());
}
});
MyAdapter = new Stud_Adapter(this,AttendStud_usn);
myListView.setAdapter(MyAdapter);
}
private static class Stud_usn{
private String usn_no="";
private boolean checked=true;
public Stud_usn(String usn_no){
this.usn_no = usn_no;
}
public String getUsn(){
return usn_no;
}
public void setChecked(boolean checked){
this.checked=checked;
}
public Object isChecked() {
// TODO Auto-generated method stub
return checked;
}
public String toString(){
return usn_no;
}
public void toggleChecked() {
// TODO Auto-generated method stub
checked = !checked;
}
}
private static class Stud_usnViewHolder{
private CheckBox checkbox;
private TextView textview;
public Stud_usnViewHolder(TextView textview, CheckBox checkbox){
this.checkbox=checkbox;
this.textview=textview;
}
public CheckBox getCheckBox() {
// TODO Auto-generated method stub
return checkbox;
}
public TextView getTextView(){
return textview;
}
}
private static class Stud_Adapter extends ArrayAdapter<Stud_usn>{
public LayoutInflater inflater;
public Stud_Adapter(Context context, List<String> attendStud_usn) {
super(context,R.layout.listdecoration,R.id.tvlistdecor);
// TODO Auto-generated constructor stub
inflater = LayoutInflater.from(context);
}
public View getView(int position, View convertView, ViewGroup parent){
Stud_usn usn = (Stud_usn) this.getItem(position);
CheckBox checkbox;
TextView textview;
if(convertView == null){
convertView = inflater.inflate(R.layout.listdecoration,null);
textview = (TextView) convertView.findViewById(R.id.tvlistdecor);
checkbox = (CheckBox) convertView.findViewById(R.id.cbusn_checked);
}
return convertView;
}
}
}
The view objects are recycled. You have to store that info sepperately. Not in the view but in the with the data you use in the adapter. When generating the views use this info to set the button state again.
You have to implement a custom adapter. Use the BaseAdapter class.
I am developing an android application which is purely web based. It needs to display HTML5 based webpages using webview which is rich in multimedia contents. when I try to play video content embedded in the webpage its all gone fine and i am also able to play video in full screen.
But my main problem starts here: When I toggled the device screen while playing fullscreen video, it suddenly exits from playback to its current web page. I am stucked here and here I am including all codes that I used as I can in hopes someone can help me.
Activity that is used: MainActivity.java
`
public class MainActivity extends Activity {
private WebView webView;
private FrameLayout customViewContainer;
private WebChromeClient.CustomViewCallback customViewCallback;
private View mCustomView;
private MyWebViewClient mWebViewClient;
private MyWebChromeClient mWebChromeClient;
/**
* Called when the activity is first created.
*/
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
customViewContainer = (FrameLayout) findViewById(R.id.customViewContainer);
webView = (WebView) findViewById(R.id.webView);
mWebViewClient = new MyWebViewClient();
webView.setWebViewClient(mWebViewClient);
mWebChromeClient = new MyWebChromeClient();
webView.setWebChromeClient(mWebChromeClient);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setAppCacheEnabled(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setSaveFormData(true);
webView.loadUrl("http://yuotube.com");
}
public boolean inCustomView() {
return (mCustomView != null);
}
public void hideCustomView() {
mWebChromeClient.onHideCustomView();
}
#Override
protected void onPause() {
super.onPause(); //To change body of overridden methods use File | Settings | File Templates.
webView.onPause();
}
#Override
protected void onResume() {
super.onResume(); //To change body of overridden methods use File | Settings | File Templates.
webView.onResume();
}
#Override
protected void onStop() {
super.onStop(); //To change body of overridden methods use File | Settings | File Templates.
if (inCustomView()) {
hideCustomView();
}
}
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
if (inCustomView()) {
hideCustomView();
return true;
}
if ((mCustomView == null) && webView.canGoBack()) {
webView.goBack();
return true;
}
}
return super.onKeyDown(keyCode, event);
}
// WebChromeClient Class
public class MyWebChromeClient extends WebChromeClient {
private Bitmap mDefaultVideoPoster;
private View mVideoProgressView;
#Override
public void onShowCustomView(View view, int requestedOrientation, CustomViewCallback callback) {
onShowCustomView(view, callback); //To change body of overridden methods use File | Settings | File Templates.
}
#Override
public void onShowCustomView(View view,CustomViewCallback callback) {
// if a view already exists then immediately terminate the new one
if (mCustomView != null) {
callback.onCustomViewHidden();
return;
}
mCustomView = view;
webView.setVisibility(View.GONE);
customViewContainer.setVisibility(View.VISIBLE);
customViewContainer.addView(view);
customViewCallback = callback;
}
#Override
public View getVideoLoadingProgressView() {
if (mVideoProgressView == null) {
LayoutInflater inflater = LayoutInflater.from(MainActivity.this);
mVideoProgressView = inflater.inflate(R.layout.video_progress, null);
}
return mVideoProgressView;
}
#Override
public void onHideCustomView() {
super.onHideCustomView(); //To change body of overridden methods use File | Settings | File Templates.
if (mCustomView == null)
return;
webView.setVisibility(View.VISIBLE);
customViewContainer.setVisibility(View.GONE);
// Hide the custom view.
mCustomView.setVisibility(View.GONE);
// Remove the custom view from its container.
customViewContainer.removeView(mCustomView);
customViewCallback.onCustomViewHidden();
mCustomView = null;
}
}
// WebViewClient Class
public class MyWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return super.shouldOverrideUrlLoading(view, url); //To change body of overridden methods use File | Settings | File Templates.
}
ProgressDialog dialog = ProgressDialog.show(MainActivity.this, "",
"Loading multimedia! Please wait...", true);
#Override
public void onPageFinished(WebView view, String url) {
dialog.dismiss();
}
}
}
web_activity.xml
<!-- View that will be hidden when video goes fullscreen -->
<RelativeLayout
android:id="#+id/nonVideoLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.example.iptvmodified.VideoEnabledWebView
android:id="#+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
<!-- View where the video will be shown when video goes fullscreen -->
<RelativeLayout
android:id="#+id/videoLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- View that will be shown while the fullscreen video loads (maybe include a spinner and a "Loading..." message) -->
<View
android:id="#+id/videoLoading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="invisible" />
</RelativeLayout>
`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: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" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
I am searching for a solution for thisand googled this to death with no progress made. Any help would be greatly appreciated.
Normally when the device is rotated your activity gets destroyed and recreated. This is probably causing the WebView to get 'kicked out of' fullscreen playback.
You need to override Activity.onConfigurationChanged and declare you want to handle orientation changes in your manifest. See the docs for details.
I use DialogFragments in my game for some popup information. It works fine on LG Nexus 4 running android 4.2 and it runs fine on the Desire S running 2.3.
It does however not run correctly on a Sony Xperia U (running 4). Here is what happens:
black spaces under dialogfragment
It does not place the dialog in the middle of the screen, which happens on all other devices, but it also renders a big black section on my screen below the dialog.
Here is my code:
public void ShowMessage(String title, String msg)
{
Bundle b = new Bundle();
b.putString("title", title);
b.putString("msg", msg);
DialogFragment dialog = new DialogFragment_MsgBox();
dialog.setArguments(b);
dialog.show(getSupportFragmentManager(), "msgbox");
}
and
public class DialogFragment_MsgBox extends android.support.v4.app.DialogFragment {
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Bundle b = getArguments();
final Dialog dialog = new Dialog(getActivity(), R.style.SetmsgDialog);
dialog.setContentView(R.layout.simpleokdialog);
if(b.containsKey("title"))
dialog.setTitle(b.getString("title"));
else
dialog.setTitle("Message");
return dialog;
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.simpleokdialog, container, false);
Bundle b = getArguments();
String msg = "";
if(b.containsKey("msg"))
{
msg = b.getString("msg");
}
TextView text = (TextView)v.findViewById(R.id.bericht);
text.setText(msg);
Button iv = (Button)v.findViewById(R.id.simpleOK);
iv.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
// When button is clicked, call up to owning activity.
getDialog().dismiss();
}
});
// TODO Auto-generated method stub
return v;
}
}
and also needed the style i use for the dialogfragment:
<style name="SetmsgDialog">
<item name="android:background">#aac6775c</item>
<item name="android:textColor">#android:color/white</item>
<item name="android:windowNoTitle">false</item>
<item name="android:textSize">14sp</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowTitleStyle">#style/setwindowTitleStyle</item>
<item name="android:windowAnimationStyle">#android:style/Animation.Dialog</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:gravity">left</item>
</style>
What can cause this? any solutions/tips or suggestions to this problem?
I have fixed this finally, it appears that some phones/provider software have different behavior in the standard themes etc. (I have seen this with sony again with text being white with shadow on a white background, very nasty looking, and now again with sony, different behavior) So If you do overload some theme, which you always do when using your own and not fill in all the variables, use all variables to get expected out comes!
I had 'forgotten':
<item name="android:windowBackground">#android:color/transparent</item>
for which the sony xperia U uses black with no transparency, while nexus 4 and desire S use transparent color.
I am new to android. My Preference Screen option is not showing. I am following below tutorial section "Preferences" and "Creating the Settings Activity"(https://wiki.oulu.fi/display/esde/List+views%2C+Intents%2C+Preferences+and+Notifications)
This is my SettingsActivity.java class
public class SettingsActivity extends Activity {
public static class SettingsFragment extends PreferenceFragment {
private SettingsFragment settingsFragment = null;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.preferences);
settingsFragment = new SettingsFragment();
// Display the fragment as the main content.
getFragmentManager().beginTransaction()
.replace(android.R.id.content, settingsFragment)
.commit();
}
}
This is the settings for Preference
<?xml version="1.0" encoding="utf-8"?>
<PreferenceCategory android:title="#string/server_settings" >
</PreferenceCategory>
<CheckBoxPreference
android:defaultValue="false"
android:key="#+id/pref_check"
android:summaryOff="#string/pref_off"
android:summaryOn="#string/pref_on" >
</CheckBoxPreference>
<EditTextPreference
android:key="#+id/pref_edit"
android:defaultValue="#string/pref_default"
android:dialogTitle="#string/edit_text_pref">
</EditTextPreference>
In the main activity I have below method for launching SettingActivity class.
// launch the settings activity
public boolean onOptionsItemSelected(MenuItem item) {
startActivity(new Intent(this, SettingsActivity.class));
//return super.onOptionsItemSelected(item);
return true;
}
Also I have added below code under main activity, onCreate method to initialize the default values for the settings, from the preferences setting file
PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
Could you help me on this issue?
I have an editor with multipage in which each page has copy paste delete actions and f3 navigation action. I create context and activate and deactivate the actions
Below is how the plugin.xml looks like :
<extension
point="org.eclipse.ui.bindings">
<key
commandId="com.sap.adt.wda.controller.ui.navigate"
contextId="com.sap.adt.wda.controller.ui.contextTabScope"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="F3">
</key>
</extension>
<extension
point="org.eclipse.ui.contexts">
<context
description="%context_navigateToController_ymsg"
id="com.sap.adt.wda.controller.ui.contextTabScope"
name="%context_navigateToController_yins"
parentId="org.eclipse.ui.contexts.window">
</context>
</extension>
It is done through activation and deactivation of context. Below is the code snippet.
private void activateHandlers() {
IContextService contextService = (IContextService) (PlatformUI.getWorkbench().getService(IContextService.class));
if (contextService != null) {
activation = contextService.activateContext(IControllerConstants.CONTEXT_TAB_ECLIPSE_CONTEXT_ID);
}
IEditorSite site = getEditor().getEditorSite();
IHandlerService service = (IHandlerService) site.getService(IHandlerService.class);
IHandlerActivation navigateHandlerActivation = service.activateHandler(NavigationHandler.COMMAND_ID, new NavigationHandler());
activatedHandlers = new ArrayList<IHandlerActivation>();
activatedHandlers.add(navigateHandlerActivation);
}
public void deactivateHandlers() {
IContextService contextService = (IContextService) (PlatformUI.getWorkbench().getService(IContextService.class));
contextService.deactivateContext(activation);
IHandlerService service = (IHandlerService) getEditor().getEditorSite().getService(IHandlerService.class);
if (activatedHandlers != null) {
service.deactivateHandlers(activatedHandlers);
activatedHandlers = null;
}
}
These two methods are called respectively from the page change to activate the context once the page is active and deactivate when the page is not active.
The problem is that it still conflicts with another opened editor as when I switch between editors, pagechange is not even called!! Please tell me what is the best way to implement this.
Add focus listener on sourceViewer of editor
focusListener = new FocusListener() {
#Override
public void focusLost(FocusEvent e) {
deactivateHandlers();
}
#Override
public void focusGained(FocusEvent arg0) {
activateHandlers();
}
};
sourceViewer.getTextWidget().addFocusListener(focusListener);
On switch of every page the focusLost and focusGained will be called.
Override activateHandlers() and deactivateHandlers() to enable and disable respective handlers for each parts of editor